xref: /wlan-driver/qca-wifi-host-cmn/gpio/core/src/wlan_gpio_api.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1*5113495bSYour Name /*
2*5113495bSYour Name  * Copyright (c) 2020, The Linux Foundation. All rights reserved.
3*5113495bSYour Name  *
4*5113495bSYour Name  * Permission to use, copy, modify, and/or distribute this software for any
5*5113495bSYour Name  * purpose with or without fee is hereby granted, provided that the above
6*5113495bSYour Name  * copyright notice and this permission notice appear in all copies.
7*5113495bSYour Name  *
8*5113495bSYour Name  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9*5113495bSYour Name  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10*5113495bSYour Name  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11*5113495bSYour Name  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12*5113495bSYour Name  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13*5113495bSYour Name  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14*5113495bSYour Name  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*5113495bSYour Name  */
16*5113495bSYour Name 
17*5113495bSYour Name /**
18*5113495bSYour Name  * DOC: wlan_gpio_api.c
19*5113495bSYour Name  */
20*5113495bSYour Name #include <wlan_gpio_api.h>
21*5113495bSYour Name #include <wlan_gpio_priv_api.h>
22*5113495bSYour Name #include <wlan_objmgr_global_obj.h>
23*5113495bSYour Name 
24*5113495bSYour Name /**
25*5113495bSYour Name  * gpio_psoc_obj_created_notification() - PSOC obj create callback
26*5113495bSYour Name  * @psoc: PSOC object
27*5113495bSYour Name  * @arg_list: Variable argument list
28*5113495bSYour Name  *
29*5113495bSYour Name  * This callback is registered with object manager during initialization to
30*5113495bSYour Name  * get notified when the object is created.
31*5113495bSYour Name  *
32*5113495bSYour Name  * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_** on error
33*5113495bSYour Name  */
34*5113495bSYour Name static QDF_STATUS
gpio_psoc_obj_created_notification(struct wlan_objmgr_psoc * psoc,void * arg_list)35*5113495bSYour Name gpio_psoc_obj_created_notification(struct wlan_objmgr_psoc *psoc,
36*5113495bSYour Name 				   void *arg_list)
37*5113495bSYour Name {
38*5113495bSYour Name 	QDF_STATUS status = QDF_STATUS_SUCCESS;
39*5113495bSYour Name 	struct gpio_psoc_priv_obj *gpio_obj;
40*5113495bSYour Name 
41*5113495bSYour Name 	gpio_obj = qdf_mem_malloc(sizeof(*gpio_obj));
42*5113495bSYour Name 	if (!gpio_obj)
43*5113495bSYour Name 		return QDF_STATUS_E_NOMEM;
44*5113495bSYour Name 
45*5113495bSYour Name 	qdf_spinlock_create(&gpio_obj->lock);
46*5113495bSYour Name 	status = wlan_objmgr_psoc_component_obj_attach(psoc,
47*5113495bSYour Name 						       WLAN_UMAC_COMP_GPIO,
48*5113495bSYour Name 						       gpio_obj,
49*5113495bSYour Name 						       QDF_STATUS_SUCCESS);
50*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(status)) {
51*5113495bSYour Name 		gpio_err("obj attach with psoc failed");
52*5113495bSYour Name 		goto gpio_psoc_attach_failed;
53*5113495bSYour Name 	}
54*5113495bSYour Name 
55*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
56*5113495bSYour Name 
57*5113495bSYour Name gpio_psoc_attach_failed:
58*5113495bSYour Name 	qdf_spinlock_destroy(&gpio_obj->lock);
59*5113495bSYour Name 	qdf_mem_free(gpio_obj);
60*5113495bSYour Name 	return status;
61*5113495bSYour Name }
62*5113495bSYour Name 
63*5113495bSYour Name /**
64*5113495bSYour Name  * gpio_psoc_obj_destroyed_notification() - obj delete callback
65*5113495bSYour Name  * @psoc: PSOC object
66*5113495bSYour Name  * @arg_list: Variable argument list
67*5113495bSYour Name  *
68*5113495bSYour Name  * This callback is registered with object manager during initialization to
69*5113495bSYour Name  * get notified when the object is deleted.
70*5113495bSYour Name  *
71*5113495bSYour Name  * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_** on error
72*5113495bSYour Name  */
73*5113495bSYour Name static QDF_STATUS
gpio_psoc_obj_destroyed_notification(struct wlan_objmgr_psoc * psoc,void * arg_list)74*5113495bSYour Name gpio_psoc_obj_destroyed_notification(struct wlan_objmgr_psoc *psoc,
75*5113495bSYour Name 				     void *arg_list)
76*5113495bSYour Name {
77*5113495bSYour Name 	QDF_STATUS status = QDF_STATUS_SUCCESS;
78*5113495bSYour Name 	struct gpio_psoc_priv_obj *gpio_obj;
79*5113495bSYour Name 
80*5113495bSYour Name 	gpio_obj = gpio_get_psoc_priv_obj(psoc);
81*5113495bSYour Name 
82*5113495bSYour Name 	if (!gpio_obj) {
83*5113495bSYour Name 		gpio_err("gpio_obj is NULL");
84*5113495bSYour Name 		return QDF_STATUS_E_FAULT;
85*5113495bSYour Name 	}
86*5113495bSYour Name 
87*5113495bSYour Name 	status = wlan_objmgr_psoc_component_obj_detach(psoc,
88*5113495bSYour Name 						       WLAN_UMAC_COMP_GPIO,
89*5113495bSYour Name 						       gpio_obj);
90*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(status))
91*5113495bSYour Name 		gpio_err("gpio_obj detach failed");
92*5113495bSYour Name 
93*5113495bSYour Name 	qdf_spinlock_destroy(&gpio_obj->lock);
94*5113495bSYour Name 	qdf_mem_free(gpio_obj);
95*5113495bSYour Name 
96*5113495bSYour Name 	return status;
97*5113495bSYour Name }
98*5113495bSYour Name 
wlan_gpio_init(void)99*5113495bSYour Name QDF_STATUS wlan_gpio_init(void)
100*5113495bSYour Name {
101*5113495bSYour Name 	QDF_STATUS status;
102*5113495bSYour Name 
103*5113495bSYour Name 	/* register psoc create handler functions. */
104*5113495bSYour Name 	status = wlan_objmgr_register_psoc_create_handler(
105*5113495bSYour Name 			WLAN_UMAC_COMP_GPIO,
106*5113495bSYour Name 			gpio_psoc_obj_created_notification,
107*5113495bSYour Name 			NULL);
108*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(status)) {
109*5113495bSYour Name 		gpio_err("register create handler failed");
110*5113495bSYour Name 		return status;
111*5113495bSYour Name 	}
112*5113495bSYour Name 
113*5113495bSYour Name 	/* register psoc delete handler functions. */
114*5113495bSYour Name 	status = wlan_objmgr_register_psoc_destroy_handler(
115*5113495bSYour Name 			WLAN_UMAC_COMP_GPIO,
116*5113495bSYour Name 			gpio_psoc_obj_destroyed_notification,
117*5113495bSYour Name 			NULL);
118*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(status)) {
119*5113495bSYour Name 		gpio_err("register destroy handler failed");
120*5113495bSYour Name 		goto fail_delete_psoc;
121*5113495bSYour Name 	}
122*5113495bSYour Name 
123*5113495bSYour Name 	return status;
124*5113495bSYour Name 
125*5113495bSYour Name fail_delete_psoc:
126*5113495bSYour Name 	wlan_objmgr_unregister_psoc_create_handler(
127*5113495bSYour Name 				WLAN_UMAC_COMP_GPIO,
128*5113495bSYour Name 				gpio_psoc_obj_created_notification,
129*5113495bSYour Name 				NULL);
130*5113495bSYour Name 	return status;
131*5113495bSYour Name }
132*5113495bSYour Name 
wlan_gpio_deinit(void)133*5113495bSYour Name QDF_STATUS wlan_gpio_deinit(void)
134*5113495bSYour Name {
135*5113495bSYour Name 	QDF_STATUS ret = QDF_STATUS_SUCCESS, status;
136*5113495bSYour Name 
137*5113495bSYour Name 	/* unregister psoc delete handler functions. */
138*5113495bSYour Name 	status = wlan_objmgr_unregister_psoc_destroy_handler(
139*5113495bSYour Name 			WLAN_UMAC_COMP_GPIO,
140*5113495bSYour Name 			gpio_psoc_obj_destroyed_notification,
141*5113495bSYour Name 			NULL);
142*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(status)) {
143*5113495bSYour Name 		gpio_err("unregister destroy handler failed");
144*5113495bSYour Name 		ret = status;
145*5113495bSYour Name 	}
146*5113495bSYour Name 
147*5113495bSYour Name 	/* unregister psoc create handler functions. */
148*5113495bSYour Name 	status = wlan_objmgr_unregister_psoc_create_handler(
149*5113495bSYour Name 			WLAN_UMAC_COMP_GPIO,
150*5113495bSYour Name 			gpio_psoc_obj_created_notification,
151*5113495bSYour Name 			NULL);
152*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(status)) {
153*5113495bSYour Name 		gpio_err("unregister create handler failed");
154*5113495bSYour Name 		ret = status;
155*5113495bSYour Name 	}
156*5113495bSYour Name 
157*5113495bSYour Name 	return ret;
158*5113495bSYour Name }
159