xref: /wlan-dirver/qca-wifi-host-cmn/qal/inc/qal_vbus_dev.h (revision 8bb055208052ae0477d645bb292c6703857bdb2f)
1 /*
2  * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /**
21  * DOC: qal_vbus_dev
22  * QCA abstraction layer (QAL) virtual bus management APIs
23  */
24 
25 #if !defined(__QAL_VBUS_DEV_H)
26 #define __QAL_VBUS_DEV_H
27 
28 /* Include Files */
29 #include <qdf_types.h>
30 #include <i_qal_vbus_dev.h>
31 
32 struct qdf_vbus_resource;
33 struct qdf_vbus_rstctl;
34 struct qdf_dev_clk;
35 struct qdf_pfm_hndl;
36 struct qdf_pfm_drv;
37 struct qdf_device_node;
38 typedef __qdf_of_gpio_flags qdf_of_gpio_flags;
39 #ifdef ENHANCED_OS_ABSTRACTION
40 /**
41  * qal_vbus_get_iorsc() - acquire io resource
42  * @devnum: Device Number
43  * @flag: Property bitmap for the io resource
44  * @devname: Device name string
45  *
46  * This function will allocate the io resource for a device
47  *
48  * Return: QDF_STATUS_SUCCESS on success
49  */
50 QDF_STATUS
51 qal_vbus_get_iorsc(int devnum, uint32_t flag, char *devname);
52 
53 /**
54  * qal_vbus_release_iorsc() - release io resource
55  * @devnum: Device Number
56  *
57  * This function will release the io resource attached to a device
58  *
59  * Return: QDF_STATUS_SUCCESS on success
60  */
61 QDF_STATUS
62 qal_vbus_release_iorsc(int devnum);
63 
64 /**
65  * qal_vbus_allocate_iorsc() - allocate io resource
66  * @pinnum: pin Number
67  * @label: pin name string
68  *
69  * This function will allocate the io resource for a device
70  *
71  * Return: QDF_STATUS_SUCCESS on success
72  */
73 QDF_STATUS
74 qal_vbus_allocate_iorsc(unsigned int pinnum, const char *label);
75 
76 /**
77  * qal_vbus_iorsc_dir_output() - set pin dirction to output
78  * @pin: pin Number
79  * @val: value
80  *
81  * This function set the gpio pin direction to output
82  *
83  * Return: 0 on success, error no on failure
84  */
85 QDF_STATUS
86 qal_vbus_iorsc_dir_output(unsigned int pin, int val);
87 
88 /**
89  * qal_vbus_iorsc_set_value() - set pin direction
90  * @pin: pin Number
91  * @val: value
92  *
93  * This function set the gpio pin direction based on value
94  *
95  * Return: QDF_STATUS_SUCCESS on success
96  */
97 QDF_STATUS
98 qal_vbus_iorsc_set_value(unsigned int pin, int val);
99 
100 /**
101  * qal_vbus_iorsc_toirq() - set irq number to gpio
102  * @pin: pin Number
103  *
104  * This function set the irq number to gpio pin
105  *
106  * Return: QDF_STATUS_SUCCESS on success
107  */
108 QDF_STATUS
109 qal_vbus_iorsc_toirq(unsigned int pin);
110 
111 /**
112  * qal_vbus_request_irq() - set interrupt handler
113  * @irqnum: irq Number
114  * @handler: function handler to be called
115  * @flags: irq flags
116  * @dev_name: device name
117  * @ctx: pointer to device context
118  * This function set up the handling of the interrupt
119  *
120  * Return: QDF_STATUS_SUCCESS on success, Error code on failure
121  */
122 QDF_STATUS
123 qal_vbus_request_irq(unsigned int irqnum,
124 		     irqreturn_t (*handler)(int irq, void *arg),
125 		     unsigned long flags, const char *dev_name,
126 		     void *ctx);
127 
128 /**
129  * __qal_vbus_free_irq() - free irq
130  * @irqnum: irq Number
131  * @ctx: pointer to device context
132  *
133  * This function free the irq number set to gpio pin
134  *
135  * Return: QDF_STATUS_SUCCESS on success
136  */
137 static inline QDF_STATUS
138 __qal_vbus_free_irq(unsigned int irqnum, void *ctx);
139 
140 /**
141  * qal_vbus_enable_devclk() - enable device clock
142  * @clk: Device clock
143  *
144  * This function will enable the clock for a device
145  *
146  * Return: QDF_STATUS_SUCCESS on success
147  */
148 QDF_STATUS
149 qal_vbus_enable_devclk(struct qdf_dev_clk *clk);
150 
151 /**
152  * qal_vbus_disable_devclk() - disable device clock
153  * @clk: Device clock
154  *
155  * This function will disable the clock for a device
156  *
157  * Return: QDF_STATUS_SUCCESS on success
158  */
159 QDF_STATUS
160 qal_vbus_disable_devclk(struct qdf_dev_clk *clk);
161 
162 /**
163  * qal_vbus_get_dev_rstctl() - get device reset control
164  * @pfhndl: Device handle
165  * @state: Device state information
166  * @rstctl: Device reset control handle
167  *
168  * This function will acquire the control to reset the device
169  *
170  * Return: QDF_STATUS_SUCCESS on success
171  */
172 QDF_STATUS
173 qal_vbus_get_dev_rstctl(struct qdf_pfm_hndl *pfhndl, const char *state,
174 			struct qdf_vbus_rstctl **rstctl);
175 
176 /**
177  * qal_vbus_release_dev_rstctl() - release device reset control
178  * @pfhndl: Device handle
179  * @rstctl: Device reset control handle
180  *
181  * This function will release the control to reset the device
182  *
183  * Return: QDF_STATUS_SUCCESS on success
184  */
185 QDF_STATUS
186 qal_vbus_release_dev_rstctl(struct qdf_pfm_hndl *pfhndl,
187 			    struct qdf_vbus_rstctl *rstctl);
188 
189 /**
190  * qal_vbus_activate_dev_rstctl() - activate device reset control
191  * @pfhndl: Device handle
192  * @rstctl: Device reset control handle
193  *
194  * This function will activate the reset control for the device
195  *
196  * Return: QDF_STATUS_SUCCESS on success
197  */
198 QDF_STATUS
199 qal_vbus_activate_dev_rstctl(struct qdf_pfm_hndl *pfhndl,
200 			     struct qdf_vbus_rstctl *rstctl);
201 
202 /**
203  * qal_vbus_deactivate_dev_rstctl() - deactivate device reset control
204  * @pfhndl: Device handle
205  * @rstctl: Device reset control handle
206  *
207  * This function will deactivate the reset control for the device
208  *
209  * Return: QDF_STATUS_SUCCESS on success
210  */
211 QDF_STATUS
212 qal_vbus_deactivate_dev_rstctl(struct qdf_pfm_hndl *pfhndl,
213 			       struct qdf_vbus_rstctl *rstctl);
214 
215 /**
216  * qal_vbus_get_resource() - get resource
217  * @pfhndl: Device handle
218  * @rsc: Resource handle
219  * @restype: Resource type
220  * @residx: Resource index
221  *
222  * This function will acquire a particular resource and attach it to the device
223  *
224  * Return: QDF_STATUS_SUCCESS on success
225  */
226 QDF_STATUS
227 qal_vbus_get_resource(struct qdf_pfm_hndl *pfhndl,
228 		      struct qdf_vbus_resource **rsc, uint32_t restype,
229 		      uint32_t residx);
230 
231 /**
232  * qal_vbus_get_irq() - get irq
233  * @pfhndl: Device handle
234  * @str: Device identifier
235  * @irq: irq number
236  *
237  * This function will acquire an irq for the device
238  *
239  * Return: QDF_STATUS_SUCCESS on success
240  */
241 QDF_STATUS
242 qal_vbus_get_irq(struct qdf_pfm_hndl *pfhndl, const char *str, int *irq);
243 
244 /**
245  * qal_vbus_register_driver() - register driver
246  * @pfdev: Device handle
247  *
248  * This function will initialize a device
249  *
250  * Return: QDF_STATUS_SUCCESS on success
251  */
252 QDF_STATUS
253 qal_vbus_register_driver(struct qdf_pfm_drv *pfdev);
254 
255 /**
256  * qal_vbus_deregister_driver() - deregister driver
257  * @pfdev: Device handle
258  *
259  * This function will deregister the driver for a device
260  *
261  * Return: QDF_STATUS_SUCCESS on success
262  */
263 QDF_STATUS
264 qal_vbus_deregister_driver(struct qdf_pfm_drv *pfdev);
265 
266 /**
267  * qal_vbus_gpio_set_value_cansleep() - assign a gpio's value
268  * @gpio: gpio whose value will be assigned
269  * @value: value to assign
270  *
271  * Return: QDF_STATUS_SUCCESS on success
272  */
273 QDF_STATUS
274 qal_vbus_gpio_set_value_cansleep(unsigned int gpio, int value);
275 
276 /**
277  * qal_vbus_rcu_read_lock() - mark the beginning of an RCU read-side critical
278  *                            section
279  *
280  * Return: QDF_STATUS_SUCCESS on success
281  */
282 QDF_STATUS
283 qal_vbus_rcu_read_lock(void);
284 
285 /**
286  * qal_vbus_rcu_read_unlock() - mark the end of an RCU read-side critical
287  *                              section
288  *
289  * Return: QDF_STATUS_SUCCESS on success
290  */
291 QDF_STATUS
292 qal_vbus_rcu_read_unlock(void);
293 
294 /**
295  * qal_vbus_of_get_named_gpio_flags() - Get a GPIO descriptor and flags
296  * for GPIO API
297  * @np: device node to get GPIO from
298  * @list_name: property name containing gpio specifier(s)
299  * @index: index of the GPIO
300  * @flags: a flags pointer to fill in
301  *
302  * The global GPIO number for the GPIO specified by its descriptor.
303  */
304 int
305 qal_vbus_of_get_named_gpio_flags(struct qdf_device_node *np,
306 				 const char *list_name,
307 				 int index, qdf_of_gpio_flags *flags);
308 #else
309 static inline QDF_STATUS
310 qal_vbus_get_iorsc(int devnum, uint32_t flag, char *devname)
311 {
312 	return __qal_vbus_get_iorsc(devnum, flag, devname);
313 }
314 
315 static inline QDF_STATUS
316 qal_vbus_allocate_iorsc(unsigned int pinnum, const char *label)
317 {
318 	return __qal_vbus_allocate_iorsc(pinnum, label);
319 }
320 
321 static inline QDF_STATUS
322 qal_vbus_iorsc_dir_output(unsigned int pin, int val)
323 {
324 	return __qal_vbus_iorsc_dir_output(pin, val);
325 }
326 
327 static inline QDF_STATUS
328 qal_vbus_iorsc_set_value(unsigned int pin, int val)
329 {
330 	return __qal_vbus_iorsc_set_value(pin, val);
331 }
332 
333 static inline QDF_STATUS
334 qal_vbus_release_iorsc(int devnum)
335 {
336 	return __qal_vbus_release_iorsc(devnum);
337 }
338 
339 static inline QDF_STATUS
340 qal_vbus_iorsc_toirq(unsigned int pin)
341 {
342 	return __qal_vbus_iorsc_toirq(pin);
343 }
344 
345 static inline QDF_STATUS
346 qal_vbus_request_irq(unsigned int irqnum,
347 		     irqreturn_t (*handler)(int irq, void *arg),
348 		     unsigned long flags, const char *dev_name, void *ctx)
349 {
350 	return __qal_vbus_request_irq(irqnum, handler, flags, dev_name, ctx);
351 }
352 
353 static inline QDF_STATUS
354 qal_vbus_free_irq(unsigned int irqnum, void *ctx)
355 {
356 	return __qal_vbus_free_irq(irqnum, ctx);
357 }
358 
359 static inline QDF_STATUS
360 qal_vbus_enable_devclk(struct qdf_dev_clk *clk)
361 {
362 	return __qal_vbus_enable_devclk(clk);
363 }
364 
365 static inline QDF_STATUS
366 qal_vbus_disable_devclk(struct qdf_dev_clk *clk)
367 {
368 	return __qal_vbus_disable_devclk(clk);
369 }
370 
371 static inline QDF_STATUS
372 qal_vbus_get_dev_rstctl(struct qdf_pfm_hndl *pfhndl, const char *state,
373 			struct qdf_vbus_rstctl **rstctl)
374 {
375 	return __qal_vbus_get_dev_rstctl(pfhndl, state, rstctl);
376 }
377 
378 static inline QDF_STATUS
379 qal_vbus_release_dev_rstctl(struct qdf_pfm_hndl *pfhndl,
380 			    struct qdf_vbus_rstctl *rstctl)
381 {
382 	return __qal_vbus_release_dev_rstctl(pfhndl, rstctl);
383 }
384 
385 static inline QDF_STATUS
386 qal_vbus_activate_dev_rstctl(struct qdf_pfm_hndl *pfhndl,
387 			     struct qdf_vbus_rstctl *rstctl)
388 {
389 	return __qal_vbus_activate_dev_rstctl(pfhndl, rstctl);
390 }
391 
392 static inline QDF_STATUS
393 qal_vbus_deactivate_dev_rstctl(struct qdf_pfm_hndl *pfhndl,
394 			       struct qdf_vbus_rstctl *rstctl)
395 {
396 	return __qal_vbus_deactivate_dev_rstctl(pfhndl, rstctl);
397 }
398 
399 static inline QDF_STATUS
400 qal_vbus_get_resource(struct qdf_pfm_hndl *pfhndl,
401 		      struct qdf_vbus_resource **rsc, uint32_t restype,
402 		      uint32_t residx)
403 {
404 	return __qal_vbus_get_resource(pfhndl, rsc, restype, residx);
405 }
406 
407 static inline QDF_STATUS
408 qal_vbus_get_irq(struct qdf_pfm_hndl *pfhndl, const char *str, int *irq)
409 {
410 	return __qal_vbus_get_irq(pfhndl, str, irq);
411 }
412 
413 static inline QDF_STATUS
414 qal_vbus_register_driver(struct qdf_pfm_drv *pfdev)
415 {
416 	return __qal_vbus_register_driver(pfdev);
417 }
418 
419 static inline QDF_STATUS
420 qal_vbus_deregister_driver(struct qdf_pfm_drv *pfdev)
421 {
422 	return __qal_vbus_deregister_driver(pfdev);
423 }
424 
425 static inline QDF_STATUS
426 qal_vbus_gpio_set_value_cansleep(unsigned int gpio, int value)
427 {
428 	return __qal_vbus_gpio_set_value_cansleep(gpio, value);
429 }
430 
431 static inline QDF_STATUS
432 qal_vbus_rcu_read_lock(void)
433 {
434 	return __qal_vbus_rcu_read_lock();
435 }
436 
437 static inline QDF_STATUS
438 qal_vbus_rcu_read_unlock(void)
439 {
440 	return __qal_vbus_rcu_read_unlock();
441 }
442 
443 static inline int
444 qal_vbus_of_get_named_gpio_flags(struct qdf_device_node *np,
445 				 const char *list_name,
446 				 int index, qdf_of_gpio_flags *flags)
447 {
448 	return __qal_vbus_of_get_named_gpio_flags(np, list_name, index, flags);
449 }
450 #endif
451 #endif  /* __QAL_VBUS_DEV_H */
452