xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852be/phl/hal_g6/hal_led.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2019 Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  *****************************************************************************/
15 #define _HAL_LED_C_
16 #include "hal_headers.h"
17 
18 #define HAL_LED_GET_CTRL_MODE(m)                                               \
19 	((m) == RTW_LED_CTRL_SW_PP_MODE                                        \
20 	     ? MAC_AX_LED_MODE_SW_CTRL_PP                                      \
21 	     : ((m) == RTW_LED_CTRL_SW_OD_MODE                                 \
22 		    ? MAC_AX_LED_MODE_SW_CTRL_OD                               \
23 		    : ((m) == RTW_LED_CTRL_HW_TX_MODE                          \
24 			   ? MAC_AX_LED_MODE_TX_ON                             \
25 			   : ((m) == RTW_LED_CTRL_HW_RX_MODE                   \
26 				  ? MAC_AX_LED_MODE_RX_ON                      \
27 				  : MAC_AX_LED_MODE_TRX_ON))))
28 
29 #define HAL_LED_GET_ID(i)                                                      \
30 	((i) == RTW_LED_ID_0 ? 0 : ((i) == RTW_LED_ID_1 ? 1 : 0))
31 
rtw_hal_led_set_ctrl_mode(void * hal,enum rtw_led_id led_id,enum rtw_led_ctrl_mode ctrl_mode)32 enum rtw_hal_status rtw_hal_led_set_ctrl_mode(void *hal, enum rtw_led_id led_id,
33 					      enum rtw_led_ctrl_mode ctrl_mode)
34 {
35 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
36 
37 	PHL_TRACE(COMP_PHL_LED, _PHL_INFO_,
38 		  "%s: led_id == %d, ctrl_mode == %d\n", __func__, led_id,
39 		  ctrl_mode);
40 
41 	if (ctrl_mode == RTW_LED_CTRL_NOT_SUPPORT)
42 		return RTW_HAL_STATUS_SUCCESS;
43 
44 	return rtw_hal_mac_led_set_ctrl_mode(
45 	    hal_info, HAL_LED_GET_CTRL_MODE(ctrl_mode), HAL_LED_GET_ID(led_id));
46 }
47 
rtw_hal_led_control(void * hal,enum rtw_led_id led_id,u8 high)48 enum rtw_hal_status rtw_hal_led_control(void *hal, enum rtw_led_id led_id,
49 					u8 high)
50 {
51 	enum rtw_hal_status status = RTW_HAL_STATUS_SUCCESS;
52 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
53 	PHL_TRACE(COMP_PHL_LED, _PHL_INFO_, "===> hal_led_ctrl()\n");
54 
55 	if (high) {
56 		PHL_TRACE(COMP_PHL_LED, _PHL_INFO_,
57 			  "hal_led_ctrl() : LED HIGH\n");
58 		status =
59 		    rtw_hal_mac_led_ctrl(hal_info, 1, HAL_LED_GET_ID(led_id));
60 	} else {
61 		PHL_TRACE(COMP_PHL_LED, _PHL_INFO_,
62 			  "hal_led_ctrl() : LED LOW\n");
63 		status =
64 		    rtw_hal_mac_led_ctrl(hal_info, 0, HAL_LED_GET_ID(led_id));
65 	}
66 
67 	if (status != RTW_HAL_STATUS_SUCCESS) {
68 		PHL_TRACE(COMP_PHL_LED, _PHL_INFO_,
69 			  "hal_led_ctrl() : rtw_hal_mac_led_ctrl() failed\n");
70 	}
71 
72 	return status;
73 }
74