1 /*
2 * Siano core API module
3 *
4 * This file contains implementation for the interface to sms core component
5 *
6 * author: Uri Shkolnik
7 *
8 * Copyright (c), 2005-2008 Siano Mobile Silicon, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation;
13 *
14 * Software distributed under the License is distributed on an "AS IS"
15 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
16 *
17 * See the GNU General Public License for more details.
18 */
19
20 #include "smscoreapi.h"
21
22 #include <linux/kernel.h>
23 #include <linux/init.h>
24 #include <linux/module.h>
25 #include <linux/moduleparam.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/delay.h>
28 #include <linux/io.h>
29 #include <linux/slab.h>
30
31 #include <linux/firmware.h>
32 #include <linux/wait.h>
33 #include <asm/byteorder.h>
34
35 #include "sms-cards.h"
36 #include "smsir.h"
37
38 struct smscore_device_notifyee_t {
39 struct list_head entry;
40 hotplug_t hotplug;
41 };
42
43 struct smscore_idlist_t {
44 struct list_head entry;
45 int id;
46 int data_type;
47 };
48
49 struct smscore_client_t {
50 struct list_head entry;
51 struct smscore_device_t *coredev;
52 void *context;
53 struct list_head idlist;
54 onresponse_t onresponse_handler;
55 onremove_t onremove_handler;
56 };
57
58 static char *siano_msgs[] = {
59 [MSG_TYPE_BASE_VAL - MSG_TYPE_BASE_VAL] = "MSG_TYPE_BASE_VAL",
60 [MSG_SMS_GET_VERSION_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_VERSION_REQ",
61 [MSG_SMS_GET_VERSION_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_VERSION_RES",
62 [MSG_SMS_MULTI_BRIDGE_CFG - MSG_TYPE_BASE_VAL] = "MSG_SMS_MULTI_BRIDGE_CFG",
63 [MSG_SMS_GPIO_CONFIG_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_CONFIG_REQ",
64 [MSG_SMS_GPIO_CONFIG_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_CONFIG_RES",
65 [MSG_SMS_GPIO_SET_LEVEL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_SET_LEVEL_REQ",
66 [MSG_SMS_GPIO_SET_LEVEL_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_SET_LEVEL_RES",
67 [MSG_SMS_GPIO_GET_LEVEL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_GET_LEVEL_REQ",
68 [MSG_SMS_GPIO_GET_LEVEL_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_GET_LEVEL_RES",
69 [MSG_SMS_EEPROM_BURN_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_EEPROM_BURN_IND",
70 [MSG_SMS_LOG_ENABLE_CHANGE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_LOG_ENABLE_CHANGE_REQ",
71 [MSG_SMS_LOG_ENABLE_CHANGE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_LOG_ENABLE_CHANGE_RES",
72 [MSG_SMS_SET_MAX_TX_MSG_LEN_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_MAX_TX_MSG_LEN_REQ",
73 [MSG_SMS_SET_MAX_TX_MSG_LEN_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_MAX_TX_MSG_LEN_RES",
74 [MSG_SMS_SPI_HALFDUPLEX_TOKEN_HOST_TO_DEVICE - MSG_TYPE_BASE_VAL] = "MSG_SMS_SPI_HALFDUPLEX_TOKEN_HOST_TO_DEVICE",
75 [MSG_SMS_SPI_HALFDUPLEX_TOKEN_DEVICE_TO_HOST - MSG_TYPE_BASE_VAL] = "MSG_SMS_SPI_HALFDUPLEX_TOKEN_DEVICE_TO_HOST",
76 [MSG_SMS_BACKGROUND_SCAN_FLAG_CHANGE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_BACKGROUND_SCAN_FLAG_CHANGE_REQ",
77 [MSG_SMS_BACKGROUND_SCAN_FLAG_CHANGE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_BACKGROUND_SCAN_FLAG_CHANGE_RES",
78 [MSG_SMS_BACKGROUND_SCAN_SIGNAL_DETECTED_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_BACKGROUND_SCAN_SIGNAL_DETECTED_IND",
79 [MSG_SMS_BACKGROUND_SCAN_NO_SIGNAL_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_BACKGROUND_SCAN_NO_SIGNAL_IND",
80 [MSG_SMS_CONFIGURE_RF_SWITCH_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CONFIGURE_RF_SWITCH_REQ",
81 [MSG_SMS_CONFIGURE_RF_SWITCH_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CONFIGURE_RF_SWITCH_RES",
82 [MSG_SMS_MRC_PATH_DISCONNECT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MRC_PATH_DISCONNECT_REQ",
83 [MSG_SMS_MRC_PATH_DISCONNECT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MRC_PATH_DISCONNECT_RES",
84 [MSG_SMS_RECEIVE_1SEG_THROUGH_FULLSEG_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_RECEIVE_1SEG_THROUGH_FULLSEG_REQ",
85 [MSG_SMS_RECEIVE_1SEG_THROUGH_FULLSEG_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_RECEIVE_1SEG_THROUGH_FULLSEG_RES",
86 [MSG_SMS_RECEIVE_VHF_VIA_VHF_INPUT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_RECEIVE_VHF_VIA_VHF_INPUT_REQ",
87 [MSG_SMS_RECEIVE_VHF_VIA_VHF_INPUT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_RECEIVE_VHF_VIA_VHF_INPUT_RES",
88 [MSG_WR_REG_RFT_REQ - MSG_TYPE_BASE_VAL] = "MSG_WR_REG_RFT_REQ",
89 [MSG_WR_REG_RFT_RES - MSG_TYPE_BASE_VAL] = "MSG_WR_REG_RFT_RES",
90 [MSG_RD_REG_RFT_REQ - MSG_TYPE_BASE_VAL] = "MSG_RD_REG_RFT_REQ",
91 [MSG_RD_REG_RFT_RES - MSG_TYPE_BASE_VAL] = "MSG_RD_REG_RFT_RES",
92 [MSG_RD_REG_ALL_RFT_REQ - MSG_TYPE_BASE_VAL] = "MSG_RD_REG_ALL_RFT_REQ",
93 [MSG_RD_REG_ALL_RFT_RES - MSG_TYPE_BASE_VAL] = "MSG_RD_REG_ALL_RFT_RES",
94 [MSG_HELP_INT - MSG_TYPE_BASE_VAL] = "MSG_HELP_INT",
95 [MSG_RUN_SCRIPT_INT - MSG_TYPE_BASE_VAL] = "MSG_RUN_SCRIPT_INT",
96 [MSG_SMS_EWS_INBAND_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_EWS_INBAND_REQ",
97 [MSG_SMS_EWS_INBAND_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_EWS_INBAND_RES",
98 [MSG_SMS_RFS_SELECT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_RFS_SELECT_REQ",
99 [MSG_SMS_RFS_SELECT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_RFS_SELECT_RES",
100 [MSG_SMS_MB_GET_VER_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_GET_VER_REQ",
101 [MSG_SMS_MB_GET_VER_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_GET_VER_RES",
102 [MSG_SMS_MB_WRITE_CFGFILE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_WRITE_CFGFILE_REQ",
103 [MSG_SMS_MB_WRITE_CFGFILE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_WRITE_CFGFILE_RES",
104 [MSG_SMS_MB_READ_CFGFILE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_READ_CFGFILE_REQ",
105 [MSG_SMS_MB_READ_CFGFILE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_READ_CFGFILE_RES",
106 [MSG_SMS_RD_MEM_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_RD_MEM_REQ",
107 [MSG_SMS_RD_MEM_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_RD_MEM_RES",
108 [MSG_SMS_WR_MEM_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_WR_MEM_REQ",
109 [MSG_SMS_WR_MEM_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_WR_MEM_RES",
110 [MSG_SMS_UPDATE_MEM_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_UPDATE_MEM_REQ",
111 [MSG_SMS_UPDATE_MEM_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_UPDATE_MEM_RES",
112 [MSG_SMS_ISDBT_ENABLE_FULL_PARAMS_SET_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_ENABLE_FULL_PARAMS_SET_REQ",
113 [MSG_SMS_ISDBT_ENABLE_FULL_PARAMS_SET_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_ENABLE_FULL_PARAMS_SET_RES",
114 [MSG_SMS_RF_TUNE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_RF_TUNE_REQ",
115 [MSG_SMS_RF_TUNE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_RF_TUNE_RES",
116 [MSG_SMS_ISDBT_ENABLE_HIGH_MOBILITY_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_ENABLE_HIGH_MOBILITY_REQ",
117 [MSG_SMS_ISDBT_ENABLE_HIGH_MOBILITY_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_ENABLE_HIGH_MOBILITY_RES",
118 [MSG_SMS_ISDBT_SB_RECEPTION_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_SB_RECEPTION_REQ",
119 [MSG_SMS_ISDBT_SB_RECEPTION_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_SB_RECEPTION_RES",
120 [MSG_SMS_GENERIC_EPROM_WRITE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GENERIC_EPROM_WRITE_REQ",
121 [MSG_SMS_GENERIC_EPROM_WRITE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GENERIC_EPROM_WRITE_RES",
122 [MSG_SMS_GENERIC_EPROM_READ_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GENERIC_EPROM_READ_REQ",
123 [MSG_SMS_GENERIC_EPROM_READ_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GENERIC_EPROM_READ_RES",
124 [MSG_SMS_EEPROM_WRITE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_EEPROM_WRITE_REQ",
125 [MSG_SMS_EEPROM_WRITE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_EEPROM_WRITE_RES",
126 [MSG_SMS_CUSTOM_READ_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CUSTOM_READ_REQ",
127 [MSG_SMS_CUSTOM_READ_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CUSTOM_READ_RES",
128 [MSG_SMS_CUSTOM_WRITE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CUSTOM_WRITE_REQ",
129 [MSG_SMS_CUSTOM_WRITE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CUSTOM_WRITE_RES",
130 [MSG_SMS_INIT_DEVICE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_INIT_DEVICE_REQ",
131 [MSG_SMS_INIT_DEVICE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_INIT_DEVICE_RES",
132 [MSG_SMS_ATSC_SET_ALL_IP_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_SET_ALL_IP_REQ",
133 [MSG_SMS_ATSC_SET_ALL_IP_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_SET_ALL_IP_RES",
134 [MSG_SMS_ATSC_START_ENSEMBLE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_START_ENSEMBLE_REQ",
135 [MSG_SMS_ATSC_START_ENSEMBLE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_START_ENSEMBLE_RES",
136 [MSG_SMS_SET_OUTPUT_MODE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_OUTPUT_MODE_REQ",
137 [MSG_SMS_SET_OUTPUT_MODE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_OUTPUT_MODE_RES",
138 [MSG_SMS_ATSC_IP_FILTER_GET_LIST_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_GET_LIST_REQ",
139 [MSG_SMS_ATSC_IP_FILTER_GET_LIST_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_GET_LIST_RES",
140 [MSG_SMS_SUB_CHANNEL_START_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SUB_CHANNEL_START_REQ",
141 [MSG_SMS_SUB_CHANNEL_START_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SUB_CHANNEL_START_RES",
142 [MSG_SMS_SUB_CHANNEL_STOP_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SUB_CHANNEL_STOP_REQ",
143 [MSG_SMS_SUB_CHANNEL_STOP_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SUB_CHANNEL_STOP_RES",
144 [MSG_SMS_ATSC_IP_FILTER_ADD_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_ADD_REQ",
145 [MSG_SMS_ATSC_IP_FILTER_ADD_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_ADD_RES",
146 [MSG_SMS_ATSC_IP_FILTER_REMOVE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_REMOVE_REQ",
147 [MSG_SMS_ATSC_IP_FILTER_REMOVE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_REMOVE_RES",
148 [MSG_SMS_ATSC_IP_FILTER_REMOVE_ALL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_REMOVE_ALL_REQ",
149 [MSG_SMS_ATSC_IP_FILTER_REMOVE_ALL_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_REMOVE_ALL_RES",
150 [MSG_SMS_WAIT_CMD - MSG_TYPE_BASE_VAL] = "MSG_SMS_WAIT_CMD",
151 [MSG_SMS_ADD_PID_FILTER_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ADD_PID_FILTER_REQ",
152 [MSG_SMS_ADD_PID_FILTER_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ADD_PID_FILTER_RES",
153 [MSG_SMS_REMOVE_PID_FILTER_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_REMOVE_PID_FILTER_REQ",
154 [MSG_SMS_REMOVE_PID_FILTER_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_REMOVE_PID_FILTER_RES",
155 [MSG_SMS_FAST_INFORMATION_CHANNEL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_FAST_INFORMATION_CHANNEL_REQ",
156 [MSG_SMS_FAST_INFORMATION_CHANNEL_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_FAST_INFORMATION_CHANNEL_RES",
157 [MSG_SMS_DAB_CHANNEL - MSG_TYPE_BASE_VAL] = "MSG_SMS_DAB_CHANNEL",
158 [MSG_SMS_GET_PID_FILTER_LIST_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_PID_FILTER_LIST_REQ",
159 [MSG_SMS_GET_PID_FILTER_LIST_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_PID_FILTER_LIST_RES",
160 [MSG_SMS_POWER_DOWN_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_DOWN_REQ",
161 [MSG_SMS_POWER_DOWN_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_DOWN_RES",
162 [MSG_SMS_ATSC_SLT_EXIST_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_SLT_EXIST_IND",
163 [MSG_SMS_ATSC_NO_SLT_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_NO_SLT_IND",
164 [MSG_SMS_GET_STATISTICS_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_STATISTICS_REQ",
165 [MSG_SMS_GET_STATISTICS_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_STATISTICS_RES",
166 [MSG_SMS_SEND_DUMP - MSG_TYPE_BASE_VAL] = "MSG_SMS_SEND_DUMP",
167 [MSG_SMS_SCAN_START_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SCAN_START_REQ",
168 [MSG_SMS_SCAN_START_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SCAN_START_RES",
169 [MSG_SMS_SCAN_STOP_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SCAN_STOP_REQ",
170 [MSG_SMS_SCAN_STOP_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SCAN_STOP_RES",
171 [MSG_SMS_SCAN_PROGRESS_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_SCAN_PROGRESS_IND",
172 [MSG_SMS_SCAN_COMPLETE_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_SCAN_COMPLETE_IND",
173 [MSG_SMS_LOG_ITEM - MSG_TYPE_BASE_VAL] = "MSG_SMS_LOG_ITEM",
174 [MSG_SMS_DAB_SUBCHANNEL_RECONFIG_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DAB_SUBCHANNEL_RECONFIG_REQ",
175 [MSG_SMS_DAB_SUBCHANNEL_RECONFIG_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DAB_SUBCHANNEL_RECONFIG_RES",
176 [MSG_SMS_HO_PER_SLICES_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_PER_SLICES_IND",
177 [MSG_SMS_HO_INBAND_POWER_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_INBAND_POWER_IND",
178 [MSG_SMS_MANUAL_DEMOD_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MANUAL_DEMOD_REQ",
179 [MSG_SMS_HO_TUNE_ON_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_TUNE_ON_REQ",
180 [MSG_SMS_HO_TUNE_ON_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_TUNE_ON_RES",
181 [MSG_SMS_HO_TUNE_OFF_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_TUNE_OFF_REQ",
182 [MSG_SMS_HO_TUNE_OFF_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_TUNE_OFF_RES",
183 [MSG_SMS_HO_PEEK_FREQ_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_PEEK_FREQ_REQ",
184 [MSG_SMS_HO_PEEK_FREQ_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_PEEK_FREQ_RES",
185 [MSG_SMS_HO_PEEK_FREQ_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_PEEK_FREQ_IND",
186 [MSG_SMS_MB_ATTEN_SET_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_ATTEN_SET_REQ",
187 [MSG_SMS_MB_ATTEN_SET_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_ATTEN_SET_RES",
188 [MSG_SMS_ENABLE_STAT_IN_I2C_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ENABLE_STAT_IN_I2C_REQ",
189 [MSG_SMS_ENABLE_STAT_IN_I2C_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ENABLE_STAT_IN_I2C_RES",
190 [MSG_SMS_SET_ANTENNA_CONFIG_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_ANTENNA_CONFIG_REQ",
191 [MSG_SMS_SET_ANTENNA_CONFIG_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_ANTENNA_CONFIG_RES",
192 [MSG_SMS_GET_STATISTICS_EX_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_STATISTICS_EX_REQ",
193 [MSG_SMS_GET_STATISTICS_EX_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_STATISTICS_EX_RES",
194 [MSG_SMS_SLEEP_RESUME_COMP_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_SLEEP_RESUME_COMP_IND",
195 [MSG_SMS_SWITCH_HOST_INTERFACE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SWITCH_HOST_INTERFACE_REQ",
196 [MSG_SMS_SWITCH_HOST_INTERFACE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SWITCH_HOST_INTERFACE_RES",
197 [MSG_SMS_DATA_DOWNLOAD_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_DOWNLOAD_REQ",
198 [MSG_SMS_DATA_DOWNLOAD_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_DOWNLOAD_RES",
199 [MSG_SMS_DATA_VALIDITY_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_VALIDITY_REQ",
200 [MSG_SMS_DATA_VALIDITY_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_VALIDITY_RES",
201 [MSG_SMS_SWDOWNLOAD_TRIGGER_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SWDOWNLOAD_TRIGGER_REQ",
202 [MSG_SMS_SWDOWNLOAD_TRIGGER_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SWDOWNLOAD_TRIGGER_RES",
203 [MSG_SMS_SWDOWNLOAD_BACKDOOR_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SWDOWNLOAD_BACKDOOR_REQ",
204 [MSG_SMS_SWDOWNLOAD_BACKDOOR_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SWDOWNLOAD_BACKDOOR_RES",
205 [MSG_SMS_GET_VERSION_EX_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_VERSION_EX_REQ",
206 [MSG_SMS_GET_VERSION_EX_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_VERSION_EX_RES",
207 [MSG_SMS_CLOCK_OUTPUT_CONFIG_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CLOCK_OUTPUT_CONFIG_REQ",
208 [MSG_SMS_CLOCK_OUTPUT_CONFIG_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CLOCK_OUTPUT_CONFIG_RES",
209 [MSG_SMS_I2C_SET_FREQ_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_I2C_SET_FREQ_REQ",
210 [MSG_SMS_I2C_SET_FREQ_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_I2C_SET_FREQ_RES",
211 [MSG_SMS_GENERIC_I2C_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GENERIC_I2C_REQ",
212 [MSG_SMS_GENERIC_I2C_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GENERIC_I2C_RES",
213 [MSG_SMS_DVBT_BDA_DATA - MSG_TYPE_BASE_VAL] = "MSG_SMS_DVBT_BDA_DATA",
214 [MSG_SW_RELOAD_REQ - MSG_TYPE_BASE_VAL] = "MSG_SW_RELOAD_REQ",
215 [MSG_SMS_DATA_MSG - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_MSG",
216 [MSG_TABLE_UPLOAD_REQ - MSG_TYPE_BASE_VAL] = "MSG_TABLE_UPLOAD_REQ",
217 [MSG_TABLE_UPLOAD_RES - MSG_TYPE_BASE_VAL] = "MSG_TABLE_UPLOAD_RES",
218 [MSG_SW_RELOAD_START_REQ - MSG_TYPE_BASE_VAL] = "MSG_SW_RELOAD_START_REQ",
219 [MSG_SW_RELOAD_START_RES - MSG_TYPE_BASE_VAL] = "MSG_SW_RELOAD_START_RES",
220 [MSG_SW_RELOAD_EXEC_REQ - MSG_TYPE_BASE_VAL] = "MSG_SW_RELOAD_EXEC_REQ",
221 [MSG_SW_RELOAD_EXEC_RES - MSG_TYPE_BASE_VAL] = "MSG_SW_RELOAD_EXEC_RES",
222 [MSG_SMS_SPI_INT_LINE_SET_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SPI_INT_LINE_SET_REQ",
223 [MSG_SMS_SPI_INT_LINE_SET_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SPI_INT_LINE_SET_RES",
224 [MSG_SMS_GPIO_CONFIG_EX_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_CONFIG_EX_REQ",
225 [MSG_SMS_GPIO_CONFIG_EX_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_CONFIG_EX_RES",
226 [MSG_SMS_WATCHDOG_ACT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_WATCHDOG_ACT_REQ",
227 [MSG_SMS_WATCHDOG_ACT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_WATCHDOG_ACT_RES",
228 [MSG_SMS_LOOPBACK_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_LOOPBACK_REQ",
229 [MSG_SMS_LOOPBACK_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_LOOPBACK_RES",
230 [MSG_SMS_RAW_CAPTURE_START_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_RAW_CAPTURE_START_REQ",
231 [MSG_SMS_RAW_CAPTURE_START_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_RAW_CAPTURE_START_RES",
232 [MSG_SMS_RAW_CAPTURE_ABORT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_RAW_CAPTURE_ABORT_REQ",
233 [MSG_SMS_RAW_CAPTURE_ABORT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_RAW_CAPTURE_ABORT_RES",
234 [MSG_SMS_RAW_CAPTURE_COMPLETE_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_RAW_CAPTURE_COMPLETE_IND",
235 [MSG_SMS_DATA_PUMP_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_PUMP_IND",
236 [MSG_SMS_DATA_PUMP_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_PUMP_REQ",
237 [MSG_SMS_DATA_PUMP_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_PUMP_RES",
238 [MSG_SMS_FLASH_DL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_FLASH_DL_REQ",
239 [MSG_SMS_EXEC_TEST_1_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_EXEC_TEST_1_REQ",
240 [MSG_SMS_EXEC_TEST_1_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_EXEC_TEST_1_RES",
241 [MSG_SMS_ENBALE_TS_INTERFACE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ENBALE_TS_INTERFACE_REQ",
242 [MSG_SMS_ENBALE_TS_INTERFACE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ENBALE_TS_INTERFACE_RES",
243 [MSG_SMS_SPI_SET_BUS_WIDTH_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SPI_SET_BUS_WIDTH_REQ",
244 [MSG_SMS_SPI_SET_BUS_WIDTH_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SPI_SET_BUS_WIDTH_RES",
245 [MSG_SMS_SEND_EMM_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SEND_EMM_REQ",
246 [MSG_SMS_SEND_EMM_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SEND_EMM_RES",
247 [MSG_SMS_DISABLE_TS_INTERFACE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DISABLE_TS_INTERFACE_REQ",
248 [MSG_SMS_DISABLE_TS_INTERFACE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DISABLE_TS_INTERFACE_RES",
249 [MSG_SMS_IS_BUF_FREE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_IS_BUF_FREE_REQ",
250 [MSG_SMS_IS_BUF_FREE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_IS_BUF_FREE_RES",
251 [MSG_SMS_EXT_ANTENNA_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_EXT_ANTENNA_REQ",
252 [MSG_SMS_EXT_ANTENNA_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_EXT_ANTENNA_RES",
253 [MSG_SMS_CMMB_GET_NET_OF_FREQ_REQ_OBSOLETE - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_NET_OF_FREQ_REQ_OBSOLETE",
254 [MSG_SMS_CMMB_GET_NET_OF_FREQ_RES_OBSOLETE - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_NET_OF_FREQ_RES_OBSOLETE",
255 [MSG_SMS_BATTERY_LEVEL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_BATTERY_LEVEL_REQ",
256 [MSG_SMS_BATTERY_LEVEL_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_BATTERY_LEVEL_RES",
257 [MSG_SMS_CMMB_INJECT_TABLE_REQ_OBSOLETE - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_INJECT_TABLE_REQ_OBSOLETE",
258 [MSG_SMS_CMMB_INJECT_TABLE_RES_OBSOLETE - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_INJECT_TABLE_RES_OBSOLETE",
259 [MSG_SMS_FM_RADIO_BLOCK_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_FM_RADIO_BLOCK_IND",
260 [MSG_SMS_HOST_NOTIFICATION_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_HOST_NOTIFICATION_IND",
261 [MSG_SMS_CMMB_GET_CONTROL_TABLE_REQ_OBSOLETE - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_CONTROL_TABLE_REQ_OBSOLETE",
262 [MSG_SMS_CMMB_GET_CONTROL_TABLE_RES_OBSOLETE - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_CONTROL_TABLE_RES_OBSOLETE",
263 [MSG_SMS_CMMB_GET_NETWORKS_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_NETWORKS_REQ",
264 [MSG_SMS_CMMB_GET_NETWORKS_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_NETWORKS_RES",
265 [MSG_SMS_CMMB_START_SERVICE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_START_SERVICE_REQ",
266 [MSG_SMS_CMMB_START_SERVICE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_START_SERVICE_RES",
267 [MSG_SMS_CMMB_STOP_SERVICE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_STOP_SERVICE_REQ",
268 [MSG_SMS_CMMB_STOP_SERVICE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_STOP_SERVICE_RES",
269 [MSG_SMS_CMMB_ADD_CHANNEL_FILTER_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_ADD_CHANNEL_FILTER_REQ",
270 [MSG_SMS_CMMB_ADD_CHANNEL_FILTER_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_ADD_CHANNEL_FILTER_RES",
271 [MSG_SMS_CMMB_REMOVE_CHANNEL_FILTER_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_REMOVE_CHANNEL_FILTER_REQ",
272 [MSG_SMS_CMMB_REMOVE_CHANNEL_FILTER_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_REMOVE_CHANNEL_FILTER_RES",
273 [MSG_SMS_CMMB_START_CONTROL_INFO_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_START_CONTROL_INFO_REQ",
274 [MSG_SMS_CMMB_START_CONTROL_INFO_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_START_CONTROL_INFO_RES",
275 [MSG_SMS_CMMB_STOP_CONTROL_INFO_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_STOP_CONTROL_INFO_REQ",
276 [MSG_SMS_CMMB_STOP_CONTROL_INFO_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_STOP_CONTROL_INFO_RES",
277 [MSG_SMS_ISDBT_TUNE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_TUNE_REQ",
278 [MSG_SMS_ISDBT_TUNE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_TUNE_RES",
279 [MSG_SMS_TRANSMISSION_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_TRANSMISSION_IND",
280 [MSG_SMS_PID_STATISTICS_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_PID_STATISTICS_IND",
281 [MSG_SMS_POWER_DOWN_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_DOWN_IND",
282 [MSG_SMS_POWER_DOWN_CONF - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_DOWN_CONF",
283 [MSG_SMS_POWER_UP_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_UP_IND",
284 [MSG_SMS_POWER_UP_CONF - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_UP_CONF",
285 [MSG_SMS_POWER_MODE_SET_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_MODE_SET_REQ",
286 [MSG_SMS_POWER_MODE_SET_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_MODE_SET_RES",
287 [MSG_SMS_DEBUG_HOST_EVENT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DEBUG_HOST_EVENT_REQ",
288 [MSG_SMS_DEBUG_HOST_EVENT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DEBUG_HOST_EVENT_RES",
289 [MSG_SMS_NEW_CRYSTAL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_NEW_CRYSTAL_REQ",
290 [MSG_SMS_NEW_CRYSTAL_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_NEW_CRYSTAL_RES",
291 [MSG_SMS_CONFIG_SPI_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CONFIG_SPI_REQ",
292 [MSG_SMS_CONFIG_SPI_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CONFIG_SPI_RES",
293 [MSG_SMS_I2C_SHORT_STAT_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_I2C_SHORT_STAT_IND",
294 [MSG_SMS_START_IR_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_START_IR_REQ",
295 [MSG_SMS_START_IR_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_START_IR_RES",
296 [MSG_SMS_IR_SAMPLES_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_IR_SAMPLES_IND",
297 [MSG_SMS_CMMB_CA_SERVICE_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_CA_SERVICE_IND",
298 [MSG_SMS_SLAVE_DEVICE_DETECTED - MSG_TYPE_BASE_VAL] = "MSG_SMS_SLAVE_DEVICE_DETECTED",
299 [MSG_SMS_INTERFACE_LOCK_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_INTERFACE_LOCK_IND",
300 [MSG_SMS_INTERFACE_UNLOCK_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_INTERFACE_UNLOCK_IND",
301 [MSG_SMS_SEND_ROSUM_BUFF_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SEND_ROSUM_BUFF_REQ",
302 [MSG_SMS_SEND_ROSUM_BUFF_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SEND_ROSUM_BUFF_RES",
303 [MSG_SMS_ROSUM_BUFF - MSG_TYPE_BASE_VAL] = "MSG_SMS_ROSUM_BUFF",
304 [MSG_SMS_SET_AES128_KEY_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_AES128_KEY_REQ",
305 [MSG_SMS_SET_AES128_KEY_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_AES128_KEY_RES",
306 [MSG_SMS_MBBMS_WRITE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MBBMS_WRITE_REQ",
307 [MSG_SMS_MBBMS_WRITE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MBBMS_WRITE_RES",
308 [MSG_SMS_MBBMS_READ_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_MBBMS_READ_IND",
309 [MSG_SMS_IQ_STREAM_START_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_IQ_STREAM_START_REQ",
310 [MSG_SMS_IQ_STREAM_START_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_IQ_STREAM_START_RES",
311 [MSG_SMS_IQ_STREAM_STOP_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_IQ_STREAM_STOP_REQ",
312 [MSG_SMS_IQ_STREAM_STOP_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_IQ_STREAM_STOP_RES",
313 [MSG_SMS_IQ_STREAM_DATA_BLOCK - MSG_TYPE_BASE_VAL] = "MSG_SMS_IQ_STREAM_DATA_BLOCK",
314 [MSG_SMS_GET_EEPROM_VERSION_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_EEPROM_VERSION_REQ",
315 [MSG_SMS_GET_EEPROM_VERSION_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_EEPROM_VERSION_RES",
316 [MSG_SMS_SIGNAL_DETECTED_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_SIGNAL_DETECTED_IND",
317 [MSG_SMS_NO_SIGNAL_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_NO_SIGNAL_IND",
318 [MSG_SMS_MRC_SHUTDOWN_SLAVE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MRC_SHUTDOWN_SLAVE_REQ",
319 [MSG_SMS_MRC_SHUTDOWN_SLAVE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MRC_SHUTDOWN_SLAVE_RES",
320 [MSG_SMS_MRC_BRINGUP_SLAVE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MRC_BRINGUP_SLAVE_REQ",
321 [MSG_SMS_MRC_BRINGUP_SLAVE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MRC_BRINGUP_SLAVE_RES",
322 [MSG_SMS_EXTERNAL_LNA_CTRL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_EXTERNAL_LNA_CTRL_REQ",
323 [MSG_SMS_EXTERNAL_LNA_CTRL_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_EXTERNAL_LNA_CTRL_RES",
324 [MSG_SMS_SET_PERIODIC_STATISTICS_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_PERIODIC_STATISTICS_REQ",
325 [MSG_SMS_SET_PERIODIC_STATISTICS_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_PERIODIC_STATISTICS_RES",
326 [MSG_SMS_CMMB_SET_AUTO_OUTPUT_TS0_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SET_AUTO_OUTPUT_TS0_REQ",
327 [MSG_SMS_CMMB_SET_AUTO_OUTPUT_TS0_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SET_AUTO_OUTPUT_TS0_RES",
328 [LOCAL_TUNE - MSG_TYPE_BASE_VAL] = "LOCAL_TUNE",
329 [LOCAL_IFFT_H_ICI - MSG_TYPE_BASE_VAL] = "LOCAL_IFFT_H_ICI",
330 [MSG_RESYNC_REQ - MSG_TYPE_BASE_VAL] = "MSG_RESYNC_REQ",
331 [MSG_SMS_CMMB_GET_MRC_STATISTICS_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_MRC_STATISTICS_REQ",
332 [MSG_SMS_CMMB_GET_MRC_STATISTICS_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_MRC_STATISTICS_RES",
333 [MSG_SMS_LOG_EX_ITEM - MSG_TYPE_BASE_VAL] = "MSG_SMS_LOG_EX_ITEM",
334 [MSG_SMS_DEVICE_DATA_LOSS_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_DEVICE_DATA_LOSS_IND",
335 [MSG_SMS_MRC_WATCHDOG_TRIGGERED_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_MRC_WATCHDOG_TRIGGERED_IND",
336 [MSG_SMS_USER_MSG_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_USER_MSG_REQ",
337 [MSG_SMS_USER_MSG_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_USER_MSG_RES",
338 [MSG_SMS_SMART_CARD_INIT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SMART_CARD_INIT_REQ",
339 [MSG_SMS_SMART_CARD_INIT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SMART_CARD_INIT_RES",
340 [MSG_SMS_SMART_CARD_WRITE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SMART_CARD_WRITE_REQ",
341 [MSG_SMS_SMART_CARD_WRITE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SMART_CARD_WRITE_RES",
342 [MSG_SMS_SMART_CARD_READ_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_SMART_CARD_READ_IND",
343 [MSG_SMS_TSE_ENABLE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_TSE_ENABLE_REQ",
344 [MSG_SMS_TSE_ENABLE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_TSE_ENABLE_RES",
345 [MSG_SMS_CMMB_GET_SHORT_STATISTICS_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_SHORT_STATISTICS_REQ",
346 [MSG_SMS_CMMB_GET_SHORT_STATISTICS_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_SHORT_STATISTICS_RES",
347 [MSG_SMS_LED_CONFIG_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_LED_CONFIG_REQ",
348 [MSG_SMS_LED_CONFIG_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_LED_CONFIG_RES",
349 [MSG_PWM_ANTENNA_REQ - MSG_TYPE_BASE_VAL] = "MSG_PWM_ANTENNA_REQ",
350 [MSG_PWM_ANTENNA_RES - MSG_TYPE_BASE_VAL] = "MSG_PWM_ANTENNA_RES",
351 [MSG_SMS_CMMB_SMD_SN_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SMD_SN_REQ",
352 [MSG_SMS_CMMB_SMD_SN_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SMD_SN_RES",
353 [MSG_SMS_CMMB_SET_CA_CW_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SET_CA_CW_REQ",
354 [MSG_SMS_CMMB_SET_CA_CW_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SET_CA_CW_RES",
355 [MSG_SMS_CMMB_SET_CA_SALT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SET_CA_SALT_REQ",
356 [MSG_SMS_CMMB_SET_CA_SALT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SET_CA_SALT_RES",
357 [MSG_SMS_NSCD_INIT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_NSCD_INIT_REQ",
358 [MSG_SMS_NSCD_INIT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_NSCD_INIT_RES",
359 [MSG_SMS_NSCD_PROCESS_SECTION_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_NSCD_PROCESS_SECTION_REQ",
360 [MSG_SMS_NSCD_PROCESS_SECTION_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_NSCD_PROCESS_SECTION_RES",
361 [MSG_SMS_DBD_CREATE_OBJECT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_CREATE_OBJECT_REQ",
362 [MSG_SMS_DBD_CREATE_OBJECT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_CREATE_OBJECT_RES",
363 [MSG_SMS_DBD_CONFIGURE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_CONFIGURE_REQ",
364 [MSG_SMS_DBD_CONFIGURE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_CONFIGURE_RES",
365 [MSG_SMS_DBD_SET_KEYS_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_SET_KEYS_REQ",
366 [MSG_SMS_DBD_SET_KEYS_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_SET_KEYS_RES",
367 [MSG_SMS_DBD_PROCESS_HEADER_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_PROCESS_HEADER_REQ",
368 [MSG_SMS_DBD_PROCESS_HEADER_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_PROCESS_HEADER_RES",
369 [MSG_SMS_DBD_PROCESS_DATA_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_PROCESS_DATA_REQ",
370 [MSG_SMS_DBD_PROCESS_DATA_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_PROCESS_DATA_RES",
371 [MSG_SMS_DBD_PROCESS_GET_DATA_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_PROCESS_GET_DATA_REQ",
372 [MSG_SMS_DBD_PROCESS_GET_DATA_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_PROCESS_GET_DATA_RES",
373 [MSG_SMS_NSCD_OPEN_SESSION_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_NSCD_OPEN_SESSION_REQ",
374 [MSG_SMS_NSCD_OPEN_SESSION_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_NSCD_OPEN_SESSION_RES",
375 [MSG_SMS_SEND_HOST_DATA_TO_DEMUX_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SEND_HOST_DATA_TO_DEMUX_REQ",
376 [MSG_SMS_SEND_HOST_DATA_TO_DEMUX_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SEND_HOST_DATA_TO_DEMUX_RES",
377 [MSG_LAST_MSG_TYPE - MSG_TYPE_BASE_VAL] = "MSG_LAST_MSG_TYPE",
378 };
379
smscore_translate_msg(enum msg_types msgtype)380 char *smscore_translate_msg(enum msg_types msgtype)
381 {
382 int i = msgtype - MSG_TYPE_BASE_VAL;
383 char *msg;
384
385 if (i < 0 || i >= ARRAY_SIZE(siano_msgs))
386 return "Unknown msg type";
387
388 msg = siano_msgs[i];
389
390 if (!*msg)
391 return "Unknown msg type";
392
393 return msg;
394 }
395 EXPORT_SYMBOL_GPL(smscore_translate_msg);
396
smscore_set_board_id(struct smscore_device_t * core,int id)397 void smscore_set_board_id(struct smscore_device_t *core, int id)
398 {
399 core->board_id = id;
400 }
401
smscore_led_state(struct smscore_device_t * core,int led)402 int smscore_led_state(struct smscore_device_t *core, int led)
403 {
404 if (led >= 0)
405 core->led_state = led;
406 return core->led_state;
407 }
408 EXPORT_SYMBOL_GPL(smscore_set_board_id);
409
smscore_get_board_id(struct smscore_device_t * core)410 int smscore_get_board_id(struct smscore_device_t *core)
411 {
412 return core->board_id;
413 }
414 EXPORT_SYMBOL_GPL(smscore_get_board_id);
415
416 struct smscore_registry_entry_t {
417 struct list_head entry;
418 char devpath[32];
419 int mode;
420 enum sms_device_type_st type;
421 };
422
423 static struct list_head g_smscore_notifyees;
424 static struct list_head g_smscore_devices;
425 static struct mutex g_smscore_deviceslock;
426
427 static struct list_head g_smscore_registry;
428 static struct mutex g_smscore_registrylock;
429
430 static int default_mode = DEVICE_MODE_NONE;
431
432 module_param(default_mode, int, 0644);
433 MODULE_PARM_DESC(default_mode, "default firmware id (device mode)");
434
smscore_find_registry(char * devpath)435 static struct smscore_registry_entry_t *smscore_find_registry(char *devpath)
436 {
437 struct smscore_registry_entry_t *entry;
438 struct list_head *next;
439
440 kmutex_lock(&g_smscore_registrylock);
441 for (next = g_smscore_registry.next;
442 next != &g_smscore_registry;
443 next = next->next) {
444 entry = (struct smscore_registry_entry_t *) next;
445 if (!strncmp(entry->devpath, devpath, sizeof(entry->devpath))) {
446 kmutex_unlock(&g_smscore_registrylock);
447 return entry;
448 }
449 }
450 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
451 if (entry) {
452 entry->mode = default_mode;
453 strlcpy(entry->devpath, devpath, sizeof(entry->devpath));
454 list_add(&entry->entry, &g_smscore_registry);
455 } else
456 pr_err("failed to create smscore_registry.\n");
457 kmutex_unlock(&g_smscore_registrylock);
458 return entry;
459 }
460
smscore_registry_getmode(char * devpath)461 int smscore_registry_getmode(char *devpath)
462 {
463 struct smscore_registry_entry_t *entry;
464
465 entry = smscore_find_registry(devpath);
466 if (entry)
467 return entry->mode;
468 else
469 pr_err("No registry found.\n");
470
471 return default_mode;
472 }
473 EXPORT_SYMBOL_GPL(smscore_registry_getmode);
474
smscore_registry_gettype(char * devpath)475 static enum sms_device_type_st smscore_registry_gettype(char *devpath)
476 {
477 struct smscore_registry_entry_t *entry;
478
479 entry = smscore_find_registry(devpath);
480 if (entry)
481 return entry->type;
482 else
483 pr_err("No registry found.\n");
484
485 return -EINVAL;
486 }
487
smscore_registry_setmode(char * devpath,int mode)488 static void smscore_registry_setmode(char *devpath, int mode)
489 {
490 struct smscore_registry_entry_t *entry;
491
492 entry = smscore_find_registry(devpath);
493 if (entry)
494 entry->mode = mode;
495 else
496 pr_err("No registry found.\n");
497 }
498
smscore_registry_settype(char * devpath,enum sms_device_type_st type)499 static void smscore_registry_settype(char *devpath,
500 enum sms_device_type_st type)
501 {
502 struct smscore_registry_entry_t *entry;
503
504 entry = smscore_find_registry(devpath);
505 if (entry)
506 entry->type = type;
507 else
508 pr_err("No registry found.\n");
509 }
510
511
list_add_locked(struct list_head * new,struct list_head * head,spinlock_t * lock)512 static void list_add_locked(struct list_head *new, struct list_head *head,
513 spinlock_t *lock)
514 {
515 unsigned long flags;
516
517 spin_lock_irqsave(lock, flags);
518
519 list_add(new, head);
520
521 spin_unlock_irqrestore(lock, flags);
522 }
523
524 /*
525 * register a client callback that called when device plugged in/unplugged
526 * NOTE: if devices exist callback is called immediately for each device
527 *
528 * @param hotplug callback
529 *
530 * return: 0 on success, <0 on error.
531 */
smscore_register_hotplug(hotplug_t hotplug)532 int smscore_register_hotplug(hotplug_t hotplug)
533 {
534 struct smscore_device_notifyee_t *notifyee;
535 struct list_head *next, *first;
536 int rc = 0;
537
538 kmutex_lock(&g_smscore_deviceslock);
539 notifyee = kmalloc(sizeof(*notifyee), GFP_KERNEL);
540 if (notifyee) {
541 /* now notify callback about existing devices */
542 first = &g_smscore_devices;
543 for (next = first->next;
544 next != first && !rc;
545 next = next->next) {
546 struct smscore_device_t *coredev =
547 (struct smscore_device_t *) next;
548 rc = hotplug(coredev, coredev->device, 1);
549 }
550
551 if (rc >= 0) {
552 notifyee->hotplug = hotplug;
553 list_add(¬ifyee->entry, &g_smscore_notifyees);
554 } else
555 kfree(notifyee);
556 } else
557 rc = -ENOMEM;
558
559 kmutex_unlock(&g_smscore_deviceslock);
560
561 return rc;
562 }
563 EXPORT_SYMBOL_GPL(smscore_register_hotplug);
564
565 /*
566 * unregister a client callback that called when device plugged in/unplugged
567 *
568 * @param hotplug callback
569 *
570 */
smscore_unregister_hotplug(hotplug_t hotplug)571 void smscore_unregister_hotplug(hotplug_t hotplug)
572 {
573 struct list_head *next, *first;
574
575 kmutex_lock(&g_smscore_deviceslock);
576
577 first = &g_smscore_notifyees;
578
579 for (next = first->next; next != first;) {
580 struct smscore_device_notifyee_t *notifyee =
581 (struct smscore_device_notifyee_t *) next;
582 next = next->next;
583
584 if (notifyee->hotplug == hotplug) {
585 list_del(¬ifyee->entry);
586 kfree(notifyee);
587 }
588 }
589
590 kmutex_unlock(&g_smscore_deviceslock);
591 }
592 EXPORT_SYMBOL_GPL(smscore_unregister_hotplug);
593
smscore_notify_clients(struct smscore_device_t * coredev)594 static void smscore_notify_clients(struct smscore_device_t *coredev)
595 {
596 struct smscore_client_t *client;
597
598 /* the client must call smscore_unregister_client from remove handler */
599 while (!list_empty(&coredev->clients)) {
600 client = (struct smscore_client_t *) coredev->clients.next;
601 client->onremove_handler(client->context);
602 }
603 }
604
smscore_notify_callbacks(struct smscore_device_t * coredev,struct device * device,int arrival)605 static int smscore_notify_callbacks(struct smscore_device_t *coredev,
606 struct device *device, int arrival)
607 {
608 struct smscore_device_notifyee_t *elem;
609 int rc = 0;
610
611 /* note: must be called under g_deviceslock */
612
613 list_for_each_entry(elem, &g_smscore_notifyees, entry) {
614 rc = elem->hotplug(coredev, device, arrival);
615 if (rc < 0)
616 break;
617 }
618
619 return rc;
620 }
621
622 static struct
smscore_createbuffer(u8 * buffer,void * common_buffer,dma_addr_t common_buffer_phys)623 smscore_buffer_t *smscore_createbuffer(u8 *buffer, void *common_buffer,
624 dma_addr_t common_buffer_phys)
625 {
626 struct smscore_buffer_t *cb;
627
628 cb = kzalloc(sizeof(*cb), GFP_KERNEL);
629 if (!cb)
630 return NULL;
631
632 cb->p = buffer;
633 cb->offset_in_common = buffer - (u8 *) common_buffer;
634 if (common_buffer_phys)
635 cb->phys = common_buffer_phys + cb->offset_in_common;
636
637 return cb;
638 }
639
640 /*
641 * creates coredev object for a device, prepares buffers,
642 * creates buffer mappings, notifies registered hotplugs about new device.
643 *
644 * @param params device pointer to struct with device specific parameters
645 * and handlers
646 * @param coredev pointer to a value that receives created coredev object
647 *
648 * return: 0 on success, <0 on error.
649 */
smscore_register_device(struct smsdevice_params_t * params,struct smscore_device_t ** coredev,gfp_t gfp_buf_flags,void * mdev)650 int smscore_register_device(struct smsdevice_params_t *params,
651 struct smscore_device_t **coredev,
652 gfp_t gfp_buf_flags,
653 void *mdev)
654 {
655 struct smscore_device_t *dev;
656 u8 *buffer;
657
658 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
659 if (!dev)
660 return -ENOMEM;
661
662 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
663 dev->media_dev = mdev;
664 #endif
665 dev->gfp_buf_flags = gfp_buf_flags;
666
667 /* init list entry so it could be safe in smscore_unregister_device */
668 INIT_LIST_HEAD(&dev->entry);
669
670 /* init queues */
671 INIT_LIST_HEAD(&dev->clients);
672 INIT_LIST_HEAD(&dev->buffers);
673
674 /* init locks */
675 spin_lock_init(&dev->clientslock);
676 spin_lock_init(&dev->bufferslock);
677
678 /* init completion events */
679 init_completion(&dev->version_ex_done);
680 init_completion(&dev->data_download_done);
681 init_completion(&dev->data_validity_done);
682 init_completion(&dev->trigger_done);
683 init_completion(&dev->init_device_done);
684 init_completion(&dev->reload_start_done);
685 init_completion(&dev->resume_done);
686 init_completion(&dev->gpio_configuration_done);
687 init_completion(&dev->gpio_set_level_done);
688 init_completion(&dev->gpio_get_level_done);
689 init_completion(&dev->ir_init_done);
690
691 /* Buffer management */
692 init_waitqueue_head(&dev->buffer_mng_waitq);
693
694 /* alloc common buffer */
695 dev->common_buffer_size = params->buffer_size * params->num_buffers;
696 if (params->usb_device)
697 buffer = kzalloc(dev->common_buffer_size, GFP_KERNEL);
698 else
699 buffer = dma_alloc_coherent(params->device,
700 dev->common_buffer_size,
701 &dev->common_buffer_phys,
702 GFP_KERNEL | dev->gfp_buf_flags);
703 if (!buffer) {
704 smscore_unregister_device(dev);
705 return -ENOMEM;
706 }
707 dev->common_buffer = buffer;
708
709 /* prepare dma buffers */
710 for (; dev->num_buffers < params->num_buffers;
711 dev->num_buffers++, buffer += params->buffer_size) {
712 struct smscore_buffer_t *cb;
713
714 cb = smscore_createbuffer(buffer, dev->common_buffer,
715 dev->common_buffer_phys);
716 if (!cb) {
717 smscore_unregister_device(dev);
718 return -ENOMEM;
719 }
720
721 smscore_putbuffer(dev, cb);
722 }
723
724 pr_debug("allocated %d buffers\n", dev->num_buffers);
725
726 dev->mode = DEVICE_MODE_NONE;
727 dev->board_id = SMS_BOARD_UNKNOWN;
728 dev->context = params->context;
729 dev->device = params->device;
730 dev->usb_device = params->usb_device;
731 dev->setmode_handler = params->setmode_handler;
732 dev->detectmode_handler = params->detectmode_handler;
733 dev->sendrequest_handler = params->sendrequest_handler;
734 dev->preload_handler = params->preload_handler;
735 dev->postload_handler = params->postload_handler;
736
737 dev->device_flags = params->flags;
738 strlcpy(dev->devpath, params->devpath, sizeof(dev->devpath));
739
740 smscore_registry_settype(dev->devpath, params->device_type);
741
742 /* add device to devices list */
743 kmutex_lock(&g_smscore_deviceslock);
744 list_add(&dev->entry, &g_smscore_devices);
745 kmutex_unlock(&g_smscore_deviceslock);
746
747 *coredev = dev;
748
749 pr_debug("device %p created\n", dev);
750
751 return 0;
752 }
753 EXPORT_SYMBOL_GPL(smscore_register_device);
754
755
smscore_sendrequest_and_wait(struct smscore_device_t * coredev,void * buffer,size_t size,struct completion * completion)756 static int smscore_sendrequest_and_wait(struct smscore_device_t *coredev,
757 void *buffer, size_t size, struct completion *completion) {
758 int rc;
759
760 if (!completion)
761 return -EINVAL;
762 init_completion(completion);
763
764 rc = coredev->sendrequest_handler(coredev->context, buffer, size);
765 if (rc < 0) {
766 pr_info("sendrequest returned error %d\n", rc);
767 return rc;
768 }
769
770 return wait_for_completion_timeout(completion,
771 msecs_to_jiffies(SMS_PROTOCOL_MAX_RAOUNDTRIP_MS)) ?
772 0 : -ETIME;
773 }
774
775 /*
776 * Starts & enables IR operations
777 *
778 * return: 0 on success, < 0 on error.
779 */
smscore_init_ir(struct smscore_device_t * coredev)780 static int smscore_init_ir(struct smscore_device_t *coredev)
781 {
782 int ir_io;
783 int rc;
784 void *buffer;
785
786 coredev->ir.dev = NULL;
787 ir_io = sms_get_board(smscore_get_board_id(coredev))->board_cfg.ir;
788 if (ir_io) {/* only if IR port exist we use IR sub-module */
789 pr_debug("IR loading\n");
790 rc = sms_ir_init(coredev);
791
792 if (rc != 0)
793 pr_err("Error initialization DTV IR sub-module\n");
794 else {
795 buffer = kmalloc(sizeof(struct sms_msg_data2) +
796 SMS_DMA_ALIGNMENT,
797 GFP_KERNEL | coredev->gfp_buf_flags);
798 if (buffer) {
799 struct sms_msg_data2 *msg =
800 (struct sms_msg_data2 *)
801 SMS_ALIGN_ADDRESS(buffer);
802
803 SMS_INIT_MSG(&msg->x_msg_header,
804 MSG_SMS_START_IR_REQ,
805 sizeof(struct sms_msg_data2));
806 msg->msg_data[0] = coredev->ir.controller;
807 msg->msg_data[1] = coredev->ir.timeout;
808
809 rc = smscore_sendrequest_and_wait(coredev, msg,
810 msg->x_msg_header. msg_length,
811 &coredev->ir_init_done);
812
813 kfree(buffer);
814 } else
815 pr_err("Sending IR initialization message failed\n");
816 }
817 } else
818 pr_info("IR port has not been detected\n");
819
820 return 0;
821 }
822
823 /*
824 * configures device features according to board configuration structure.
825 *
826 * @param coredev pointer to a coredev object returned by
827 * smscore_register_device
828 *
829 * return: 0 on success, <0 on error.
830 */
smscore_configure_board(struct smscore_device_t * coredev)831 static int smscore_configure_board(struct smscore_device_t *coredev)
832 {
833 struct sms_board *board;
834
835 board = sms_get_board(coredev->board_id);
836 if (!board) {
837 pr_err("no board configuration exist.\n");
838 return -EINVAL;
839 }
840
841 if (board->mtu) {
842 struct sms_msg_data mtu_msg;
843 pr_debug("set max transmit unit %d\n", board->mtu);
844
845 mtu_msg.x_msg_header.msg_src_id = 0;
846 mtu_msg.x_msg_header.msg_dst_id = HIF_TASK;
847 mtu_msg.x_msg_header.msg_flags = 0;
848 mtu_msg.x_msg_header.msg_type = MSG_SMS_SET_MAX_TX_MSG_LEN_REQ;
849 mtu_msg.x_msg_header.msg_length = sizeof(mtu_msg);
850 mtu_msg.msg_data[0] = board->mtu;
851
852 coredev->sendrequest_handler(coredev->context, &mtu_msg,
853 sizeof(mtu_msg));
854 }
855
856 if (board->crystal) {
857 struct sms_msg_data crys_msg;
858 pr_debug("set crystal value %d\n", board->crystal);
859
860 SMS_INIT_MSG(&crys_msg.x_msg_header,
861 MSG_SMS_NEW_CRYSTAL_REQ,
862 sizeof(crys_msg));
863 crys_msg.msg_data[0] = board->crystal;
864
865 coredev->sendrequest_handler(coredev->context, &crys_msg,
866 sizeof(crys_msg));
867 }
868
869 return 0;
870 }
871
872 /*
873 * sets initial device mode and notifies client hotplugs that device is ready
874 *
875 * @param coredev pointer to a coredev object returned by
876 * smscore_register_device
877 *
878 * return: 0 on success, <0 on error.
879 */
smscore_start_device(struct smscore_device_t * coredev)880 int smscore_start_device(struct smscore_device_t *coredev)
881 {
882 int rc;
883 int board_id = smscore_get_board_id(coredev);
884 int mode = smscore_registry_getmode(coredev->devpath);
885
886 /* Device is initialized as DEVICE_MODE_NONE */
887 if (board_id != SMS_BOARD_UNKNOWN && mode == DEVICE_MODE_NONE)
888 mode = sms_get_board(board_id)->default_mode;
889
890 rc = smscore_set_device_mode(coredev, mode);
891 if (rc < 0) {
892 pr_info("set device mode failed , rc %d\n", rc);
893 return rc;
894 }
895 rc = smscore_configure_board(coredev);
896 if (rc < 0) {
897 pr_info("configure board failed , rc %d\n", rc);
898 return rc;
899 }
900
901 kmutex_lock(&g_smscore_deviceslock);
902
903 rc = smscore_notify_callbacks(coredev, coredev->device, 1);
904 smscore_init_ir(coredev);
905
906 pr_debug("device %p started, rc %d\n", coredev, rc);
907
908 kmutex_unlock(&g_smscore_deviceslock);
909
910 return rc;
911 }
912 EXPORT_SYMBOL_GPL(smscore_start_device);
913
914
smscore_load_firmware_family2(struct smscore_device_t * coredev,void * buffer,size_t size)915 static int smscore_load_firmware_family2(struct smscore_device_t *coredev,
916 void *buffer, size_t size)
917 {
918 struct sms_firmware *firmware = (struct sms_firmware *) buffer;
919 struct sms_msg_data5 *msg;
920 u32 mem_address, calc_checksum = 0;
921 u32 i, *ptr;
922 u8 *payload = firmware->payload;
923 int rc = 0;
924 firmware->start_address = le32_to_cpup((__le32 *)&firmware->start_address);
925 firmware->length = le32_to_cpup((__le32 *)&firmware->length);
926
927 mem_address = firmware->start_address;
928
929 pr_debug("loading FW to addr 0x%x size %d\n",
930 mem_address, firmware->length);
931 if (coredev->preload_handler) {
932 rc = coredev->preload_handler(coredev->context);
933 if (rc < 0)
934 return rc;
935 }
936
937 /* PAGE_SIZE buffer shall be enough and dma aligned */
938 msg = kmalloc(PAGE_SIZE, GFP_KERNEL | coredev->gfp_buf_flags);
939 if (!msg)
940 return -ENOMEM;
941
942 if (coredev->mode != DEVICE_MODE_NONE) {
943 pr_debug("sending reload command.\n");
944 SMS_INIT_MSG(&msg->x_msg_header, MSG_SW_RELOAD_START_REQ,
945 sizeof(struct sms_msg_hdr));
946 rc = smscore_sendrequest_and_wait(coredev, msg,
947 msg->x_msg_header.msg_length,
948 &coredev->reload_start_done);
949 if (rc < 0) {
950 pr_err("device reload failed, rc %d\n", rc);
951 goto exit_fw_download;
952 }
953 mem_address = *(u32 *) &payload[20];
954 }
955
956 for (i = 0, ptr = (u32 *)firmware->payload; i < firmware->length/4 ;
957 i++, ptr++)
958 calc_checksum += *ptr;
959
960 while (size && rc >= 0) {
961 struct sms_data_download *data_msg =
962 (struct sms_data_download *) msg;
963 int payload_size = min_t(int, size, SMS_MAX_PAYLOAD_SIZE);
964
965 SMS_INIT_MSG(&msg->x_msg_header, MSG_SMS_DATA_DOWNLOAD_REQ,
966 (u16)(sizeof(struct sms_msg_hdr) +
967 sizeof(u32) + payload_size));
968
969 data_msg->mem_addr = mem_address;
970 memcpy(data_msg->payload, payload, payload_size);
971
972 rc = smscore_sendrequest_and_wait(coredev, data_msg,
973 data_msg->x_msg_header.msg_length,
974 &coredev->data_download_done);
975
976 payload += payload_size;
977 size -= payload_size;
978 mem_address += payload_size;
979 }
980
981 if (rc < 0)
982 goto exit_fw_download;
983
984 pr_debug("sending MSG_SMS_DATA_VALIDITY_REQ expecting 0x%x\n",
985 calc_checksum);
986 SMS_INIT_MSG(&msg->x_msg_header, MSG_SMS_DATA_VALIDITY_REQ,
987 sizeof(msg->x_msg_header) +
988 sizeof(u32) * 3);
989 msg->msg_data[0] = firmware->start_address;
990 /* Entry point */
991 msg->msg_data[1] = firmware->length;
992 msg->msg_data[2] = 0; /* Regular checksum*/
993 rc = smscore_sendrequest_and_wait(coredev, msg,
994 msg->x_msg_header.msg_length,
995 &coredev->data_validity_done);
996 if (rc < 0)
997 goto exit_fw_download;
998
999 if (coredev->mode == DEVICE_MODE_NONE) {
1000 pr_debug("sending MSG_SMS_SWDOWNLOAD_TRIGGER_REQ\n");
1001 SMS_INIT_MSG(&msg->x_msg_header,
1002 MSG_SMS_SWDOWNLOAD_TRIGGER_REQ,
1003 sizeof(*msg));
1004
1005 msg->msg_data[0] = firmware->start_address;
1006 /* Entry point */
1007 msg->msg_data[1] = 6; /* Priority */
1008 msg->msg_data[2] = 0x200; /* Stack size */
1009 msg->msg_data[3] = 0; /* Parameter */
1010 msg->msg_data[4] = 4; /* Task ID */
1011
1012 rc = smscore_sendrequest_and_wait(coredev, msg,
1013 msg->x_msg_header.msg_length,
1014 &coredev->trigger_done);
1015 } else {
1016 SMS_INIT_MSG(&msg->x_msg_header, MSG_SW_RELOAD_EXEC_REQ,
1017 sizeof(struct sms_msg_hdr));
1018 rc = coredev->sendrequest_handler(coredev->context, msg,
1019 msg->x_msg_header.msg_length);
1020 }
1021
1022 if (rc < 0)
1023 goto exit_fw_download;
1024
1025 /*
1026 * backward compatibility - wait to device_ready_done for
1027 * not more than 400 ms
1028 */
1029 msleep(400);
1030
1031 exit_fw_download:
1032 kfree(msg);
1033
1034 if (coredev->postload_handler) {
1035 pr_debug("rc=%d, postload=0x%p\n",
1036 rc, coredev->postload_handler);
1037 if (rc >= 0)
1038 return coredev->postload_handler(coredev->context);
1039 }
1040
1041 pr_debug("rc=%d\n", rc);
1042 return rc;
1043 }
1044
1045 static char *smscore_fw_lkup[][DEVICE_MODE_MAX] = {
1046 [SMS_NOVA_A0] = {
1047 [DEVICE_MODE_DVBT] = SMS_FW_DVB_NOVA_12MHZ,
1048 [DEVICE_MODE_DVBH] = SMS_FW_DVB_NOVA_12MHZ,
1049 [DEVICE_MODE_DAB_TDMB] = SMS_FW_TDMB_NOVA_12MHZ,
1050 [DEVICE_MODE_DVBT_BDA] = SMS_FW_DVB_NOVA_12MHZ,
1051 [DEVICE_MODE_ISDBT] = SMS_FW_ISDBT_NOVA_12MHZ,
1052 [DEVICE_MODE_ISDBT_BDA] = SMS_FW_ISDBT_NOVA_12MHZ,
1053 },
1054 [SMS_NOVA_B0] = {
1055 [DEVICE_MODE_DVBT] = SMS_FW_DVB_NOVA_12MHZ_B0,
1056 [DEVICE_MODE_DVBH] = SMS_FW_DVB_NOVA_12MHZ_B0,
1057 [DEVICE_MODE_DAB_TDMB] = SMS_FW_TDMB_NOVA_12MHZ_B0,
1058 [DEVICE_MODE_DVBT_BDA] = SMS_FW_DVB_NOVA_12MHZ_B0,
1059 [DEVICE_MODE_ISDBT] = SMS_FW_ISDBT_NOVA_12MHZ_B0,
1060 [DEVICE_MODE_ISDBT_BDA] = SMS_FW_ISDBT_NOVA_12MHZ_B0,
1061 [DEVICE_MODE_FM_RADIO] = SMS_FW_FM_RADIO,
1062 [DEVICE_MODE_FM_RADIO_BDA] = SMS_FW_FM_RADIO,
1063 },
1064 [SMS_VEGA] = {
1065 [DEVICE_MODE_CMMB] = SMS_FW_CMMB_VEGA_12MHZ,
1066 },
1067 [SMS_VENICE] = {
1068 [DEVICE_MODE_CMMB] = SMS_FW_CMMB_VENICE_12MHZ,
1069 },
1070 [SMS_MING] = {
1071 [DEVICE_MODE_CMMB] = SMS_FW_CMMB_MING_APP,
1072 },
1073 [SMS_PELE] = {
1074 [DEVICE_MODE_ISDBT] = SMS_FW_ISDBT_PELE,
1075 [DEVICE_MODE_ISDBT_BDA] = SMS_FW_ISDBT_PELE,
1076 },
1077 [SMS_RIO] = {
1078 [DEVICE_MODE_DVBT] = SMS_FW_DVB_RIO,
1079 [DEVICE_MODE_DVBH] = SMS_FW_DVBH_RIO,
1080 [DEVICE_MODE_DVBT_BDA] = SMS_FW_DVB_RIO,
1081 [DEVICE_MODE_ISDBT] = SMS_FW_ISDBT_RIO,
1082 [DEVICE_MODE_ISDBT_BDA] = SMS_FW_ISDBT_RIO,
1083 [DEVICE_MODE_FM_RADIO] = SMS_FW_FM_RADIO_RIO,
1084 [DEVICE_MODE_FM_RADIO_BDA] = SMS_FW_FM_RADIO_RIO,
1085 },
1086 [SMS_DENVER_1530] = {
1087 [DEVICE_MODE_ATSC] = SMS_FW_ATSC_DENVER,
1088 },
1089 [SMS_DENVER_2160] = {
1090 [DEVICE_MODE_DAB_TDMB] = SMS_FW_TDMB_DENVER,
1091 },
1092 };
1093
1094 /*
1095 * get firmware file name from one of the two mechanisms : sms_boards or
1096 * smscore_fw_lkup.
1097 * @param coredev pointer to a coredev object returned by
1098 * smscore_register_device
1099 * @param mode requested mode of operation
1100 * @param lookup if 1, always get the fw filename from smscore_fw_lkup
1101 * table. if 0, try first to get from sms_boards
1102 *
1103 * return: 0 on success, <0 on error.
1104 */
smscore_get_fw_filename(struct smscore_device_t * coredev,int mode)1105 static char *smscore_get_fw_filename(struct smscore_device_t *coredev,
1106 int mode)
1107 {
1108 char **fw;
1109 int board_id = smscore_get_board_id(coredev);
1110 enum sms_device_type_st type;
1111
1112 type = smscore_registry_gettype(coredev->devpath);
1113
1114 /* Prevent looking outside the smscore_fw_lkup table */
1115 if (type <= SMS_UNKNOWN_TYPE || type >= SMS_NUM_OF_DEVICE_TYPES)
1116 return NULL;
1117 if (mode <= DEVICE_MODE_NONE || mode >= DEVICE_MODE_MAX)
1118 return NULL;
1119
1120 pr_debug("trying to get fw name from sms_boards board_id %d mode %d\n",
1121 board_id, mode);
1122 fw = sms_get_board(board_id)->fw;
1123 if (!fw || !fw[mode]) {
1124 pr_debug("cannot find fw name in sms_boards, getting from lookup table mode %d type %d\n",
1125 mode, type);
1126 return smscore_fw_lkup[type][mode];
1127 }
1128
1129 return fw[mode];
1130 }
1131
1132 /*
1133 * loads specified firmware into a buffer and calls device loadfirmware_handler
1134 *
1135 * @param coredev pointer to a coredev object returned by
1136 * smscore_register_device
1137 * @param filename null-terminated string specifies firmware file name
1138 * @param loadfirmware_handler device handler that loads firmware
1139 *
1140 * return: 0 on success, <0 on error.
1141 */
smscore_load_firmware_from_file(struct smscore_device_t * coredev,int mode,loadfirmware_t loadfirmware_handler)1142 static int smscore_load_firmware_from_file(struct smscore_device_t *coredev,
1143 int mode,
1144 loadfirmware_t loadfirmware_handler)
1145 {
1146 int rc = -ENOENT;
1147 u8 *fw_buf;
1148 u32 fw_buf_size;
1149 const struct firmware *fw;
1150
1151 char *fw_filename = smscore_get_fw_filename(coredev, mode);
1152 if (!fw_filename) {
1153 pr_err("mode %d not supported on this device\n", mode);
1154 return -ENOENT;
1155 }
1156 pr_debug("Firmware name: %s\n", fw_filename);
1157
1158 if (!loadfirmware_handler &&
1159 !(coredev->device_flags & SMS_DEVICE_FAMILY2))
1160 return -EINVAL;
1161
1162 rc = request_firmware(&fw, fw_filename, coredev->device);
1163 if (rc < 0) {
1164 pr_err("failed to open firmware file '%s'\n", fw_filename);
1165 return rc;
1166 }
1167 pr_debug("read fw %s, buffer size=0x%zx\n", fw_filename, fw->size);
1168 fw_buf = kmalloc(ALIGN(fw->size + sizeof(struct sms_firmware),
1169 SMS_ALLOC_ALIGNMENT), GFP_KERNEL | coredev->gfp_buf_flags);
1170 if (!fw_buf) {
1171 pr_err("failed to allocate firmware buffer\n");
1172 rc = -ENOMEM;
1173 } else {
1174 memcpy(fw_buf, fw->data, fw->size);
1175 fw_buf_size = fw->size;
1176
1177 rc = (coredev->device_flags & SMS_DEVICE_FAMILY2) ?
1178 smscore_load_firmware_family2(coredev, fw_buf, fw_buf_size)
1179 : loadfirmware_handler(coredev->context, fw_buf,
1180 fw_buf_size);
1181 }
1182
1183 kfree(fw_buf);
1184 release_firmware(fw);
1185
1186 return rc;
1187 }
1188
1189 /*
1190 * notifies all clients registered with the device, notifies hotplugs,
1191 * frees all buffers and coredev object
1192 *
1193 * @param coredev pointer to a coredev object returned by
1194 * smscore_register_device
1195 *
1196 * return: 0 on success, <0 on error.
1197 */
smscore_unregister_device(struct smscore_device_t * coredev)1198 void smscore_unregister_device(struct smscore_device_t *coredev)
1199 {
1200 struct smscore_buffer_t *cb;
1201 int num_buffers = 0;
1202 int retry = 0;
1203
1204 kmutex_lock(&g_smscore_deviceslock);
1205
1206 /* Release input device (IR) resources */
1207 sms_ir_exit(coredev);
1208
1209 smscore_notify_clients(coredev);
1210 smscore_notify_callbacks(coredev, NULL, 0);
1211
1212 /* at this point all buffers should be back
1213 * onresponse must no longer be called */
1214
1215 while (1) {
1216 while (!list_empty(&coredev->buffers)) {
1217 cb = (struct smscore_buffer_t *) coredev->buffers.next;
1218 list_del(&cb->entry);
1219 kfree(cb);
1220 num_buffers++;
1221 }
1222 if (num_buffers == coredev->num_buffers)
1223 break;
1224 if (++retry > 10) {
1225 pr_info("exiting although not all buffers released.\n");
1226 break;
1227 }
1228
1229 pr_debug("waiting for %d buffer(s)\n",
1230 coredev->num_buffers - num_buffers);
1231 kmutex_unlock(&g_smscore_deviceslock);
1232 msleep(100);
1233 kmutex_lock(&g_smscore_deviceslock);
1234 }
1235
1236 pr_debug("freed %d buffers\n", num_buffers);
1237
1238 if (coredev->common_buffer) {
1239 if (coredev->usb_device)
1240 kfree(coredev->common_buffer);
1241 else
1242 dma_free_coherent(coredev->device,
1243 coredev->common_buffer_size,
1244 coredev->common_buffer,
1245 coredev->common_buffer_phys);
1246 }
1247 kfree(coredev->fw_buf);
1248
1249 list_del(&coredev->entry);
1250 kfree(coredev);
1251
1252 kmutex_unlock(&g_smscore_deviceslock);
1253
1254 pr_debug("device %p destroyed\n", coredev);
1255 }
1256 EXPORT_SYMBOL_GPL(smscore_unregister_device);
1257
smscore_detect_mode(struct smscore_device_t * coredev)1258 static int smscore_detect_mode(struct smscore_device_t *coredev)
1259 {
1260 void *buffer = kmalloc(sizeof(struct sms_msg_hdr) + SMS_DMA_ALIGNMENT,
1261 GFP_KERNEL | coredev->gfp_buf_flags);
1262 struct sms_msg_hdr *msg =
1263 (struct sms_msg_hdr *) SMS_ALIGN_ADDRESS(buffer);
1264 int rc;
1265
1266 if (!buffer)
1267 return -ENOMEM;
1268
1269 SMS_INIT_MSG(msg, MSG_SMS_GET_VERSION_EX_REQ,
1270 sizeof(struct sms_msg_hdr));
1271
1272 rc = smscore_sendrequest_and_wait(coredev, msg, msg->msg_length,
1273 &coredev->version_ex_done);
1274 if (rc == -ETIME) {
1275 pr_err("MSG_SMS_GET_VERSION_EX_REQ failed first try\n");
1276
1277 if (wait_for_completion_timeout(&coredev->resume_done,
1278 msecs_to_jiffies(5000))) {
1279 rc = smscore_sendrequest_and_wait(
1280 coredev, msg, msg->msg_length,
1281 &coredev->version_ex_done);
1282 if (rc < 0)
1283 pr_err("MSG_SMS_GET_VERSION_EX_REQ failed second try, rc %d\n",
1284 rc);
1285 } else
1286 rc = -ETIME;
1287 }
1288
1289 kfree(buffer);
1290
1291 return rc;
1292 }
1293
1294 /*
1295 * send init device request and wait for response
1296 *
1297 * @param coredev pointer to a coredev object returned by
1298 * smscore_register_device
1299 * @param mode requested mode of operation
1300 *
1301 * return: 0 on success, <0 on error.
1302 */
smscore_init_device(struct smscore_device_t * coredev,int mode)1303 static int smscore_init_device(struct smscore_device_t *coredev, int mode)
1304 {
1305 void *buffer;
1306 struct sms_msg_data *msg;
1307 int rc = 0;
1308
1309 buffer = kmalloc(sizeof(struct sms_msg_data) +
1310 SMS_DMA_ALIGNMENT, GFP_KERNEL | coredev->gfp_buf_flags);
1311 if (!buffer)
1312 return -ENOMEM;
1313
1314 msg = (struct sms_msg_data *)SMS_ALIGN_ADDRESS(buffer);
1315 SMS_INIT_MSG(&msg->x_msg_header, MSG_SMS_INIT_DEVICE_REQ,
1316 sizeof(struct sms_msg_data));
1317 msg->msg_data[0] = mode;
1318
1319 rc = smscore_sendrequest_and_wait(coredev, msg,
1320 msg->x_msg_header. msg_length,
1321 &coredev->init_device_done);
1322
1323 kfree(buffer);
1324 return rc;
1325 }
1326
1327 /*
1328 * calls device handler to change mode of operation
1329 * NOTE: stellar/usb may disconnect when changing mode
1330 *
1331 * @param coredev pointer to a coredev object returned by
1332 * smscore_register_device
1333 * @param mode requested mode of operation
1334 *
1335 * return: 0 on success, <0 on error.
1336 */
smscore_set_device_mode(struct smscore_device_t * coredev,int mode)1337 int smscore_set_device_mode(struct smscore_device_t *coredev, int mode)
1338 {
1339 int rc = 0;
1340
1341 pr_debug("set device mode to %d\n", mode);
1342 if (coredev->device_flags & SMS_DEVICE_FAMILY2) {
1343 if (mode <= DEVICE_MODE_NONE || mode >= DEVICE_MODE_MAX) {
1344 pr_err("invalid mode specified %d\n", mode);
1345 return -EINVAL;
1346 }
1347
1348 smscore_registry_setmode(coredev->devpath, mode);
1349
1350 if (!(coredev->device_flags & SMS_DEVICE_NOT_READY)) {
1351 rc = smscore_detect_mode(coredev);
1352 if (rc < 0) {
1353 pr_err("mode detect failed %d\n", rc);
1354 return rc;
1355 }
1356 }
1357
1358 if (coredev->mode == mode) {
1359 pr_debug("device mode %d already set\n", mode);
1360 return 0;
1361 }
1362
1363 if (!(coredev->modes_supported & (1 << mode))) {
1364 rc = smscore_load_firmware_from_file(coredev,
1365 mode, NULL);
1366 if (rc >= 0)
1367 pr_debug("firmware download success\n");
1368 } else {
1369 pr_debug("mode %d is already supported by running firmware\n",
1370 mode);
1371 }
1372 if (coredev->fw_version >= 0x800) {
1373 rc = smscore_init_device(coredev, mode);
1374 if (rc < 0)
1375 pr_err("device init failed, rc %d.\n", rc);
1376 }
1377 } else {
1378 if (mode <= DEVICE_MODE_NONE || mode >= DEVICE_MODE_MAX) {
1379 pr_err("invalid mode specified %d\n", mode);
1380 return -EINVAL;
1381 }
1382
1383 smscore_registry_setmode(coredev->devpath, mode);
1384
1385 if (coredev->detectmode_handler)
1386 coredev->detectmode_handler(coredev->context,
1387 &coredev->mode);
1388
1389 if (coredev->mode != mode && coredev->setmode_handler)
1390 rc = coredev->setmode_handler(coredev->context, mode);
1391 }
1392
1393 if (rc >= 0) {
1394 char *buffer;
1395 coredev->mode = mode;
1396 coredev->device_flags &= ~SMS_DEVICE_NOT_READY;
1397
1398 buffer = kmalloc(sizeof(struct sms_msg_data) +
1399 SMS_DMA_ALIGNMENT, GFP_KERNEL | coredev->gfp_buf_flags);
1400 if (buffer) {
1401 struct sms_msg_data *msg = (struct sms_msg_data *) SMS_ALIGN_ADDRESS(buffer);
1402
1403 SMS_INIT_MSG(&msg->x_msg_header, MSG_SMS_INIT_DEVICE_REQ,
1404 sizeof(struct sms_msg_data));
1405 msg->msg_data[0] = mode;
1406
1407 rc = smscore_sendrequest_and_wait(
1408 coredev, msg, msg->x_msg_header.msg_length,
1409 &coredev->init_device_done);
1410
1411 kfree(buffer);
1412 }
1413 }
1414
1415 if (rc < 0)
1416 pr_err("return error code %d.\n", rc);
1417 else
1418 pr_debug("Success setting device mode.\n");
1419
1420 return rc;
1421 }
1422
1423 /*
1424 * calls device handler to get current mode of operation
1425 *
1426 * @param coredev pointer to a coredev object returned by
1427 * smscore_register_device
1428 *
1429 * return: current mode
1430 */
smscore_get_device_mode(struct smscore_device_t * coredev)1431 int smscore_get_device_mode(struct smscore_device_t *coredev)
1432 {
1433 return coredev->mode;
1434 }
1435 EXPORT_SYMBOL_GPL(smscore_get_device_mode);
1436
1437 /*
1438 * find client by response id & type within the clients list.
1439 * return client handle or NULL.
1440 *
1441 * @param coredev pointer to a coredev object returned by
1442 * smscore_register_device
1443 * @param data_type client data type (SMS_DONT_CARE for all types)
1444 * @param id client id (SMS_DONT_CARE for all id)
1445 *
1446 */
1447 static struct
smscore_find_client(struct smscore_device_t * coredev,int data_type,int id)1448 smscore_client_t *smscore_find_client(struct smscore_device_t *coredev,
1449 int data_type, int id)
1450 {
1451 struct list_head *first;
1452 struct smscore_client_t *client;
1453 unsigned long flags;
1454 struct list_head *firstid;
1455 struct smscore_idlist_t *client_id;
1456
1457 spin_lock_irqsave(&coredev->clientslock, flags);
1458 first = &coredev->clients;
1459 list_for_each_entry(client, first, entry) {
1460 firstid = &client->idlist;
1461 list_for_each_entry(client_id, firstid, entry) {
1462 if ((client_id->id == id) &&
1463 (client_id->data_type == data_type ||
1464 (client_id->data_type == 0)))
1465 goto found;
1466 }
1467 }
1468 client = NULL;
1469 found:
1470 spin_unlock_irqrestore(&coredev->clientslock, flags);
1471 return client;
1472 }
1473
1474 /*
1475 * find client by response id/type, call clients onresponse handler
1476 * return buffer to pool on error
1477 *
1478 * @param coredev pointer to a coredev object returned by
1479 * smscore_register_device
1480 * @param cb pointer to response buffer descriptor
1481 *
1482 */
smscore_onresponse(struct smscore_device_t * coredev,struct smscore_buffer_t * cb)1483 void smscore_onresponse(struct smscore_device_t *coredev,
1484 struct smscore_buffer_t *cb) {
1485 struct sms_msg_hdr *phdr = (struct sms_msg_hdr *) ((u8 *) cb->p
1486 + cb->offset);
1487 struct smscore_client_t *client;
1488 int rc = -EBUSY;
1489 static unsigned long last_sample_time; /* = 0; */
1490 static int data_total; /* = 0; */
1491 unsigned long time_now = jiffies_to_msecs(jiffies);
1492
1493 if (!last_sample_time)
1494 last_sample_time = time_now;
1495
1496 if (time_now - last_sample_time > 10000) {
1497 pr_debug("data rate %d bytes/secs\n",
1498 (int)((data_total * 1000) /
1499 (time_now - last_sample_time)));
1500
1501 last_sample_time = time_now;
1502 data_total = 0;
1503 }
1504
1505 data_total += cb->size;
1506 /* Do we need to re-route? */
1507 if ((phdr->msg_type == MSG_SMS_HO_PER_SLICES_IND) ||
1508 (phdr->msg_type == MSG_SMS_TRANSMISSION_IND)) {
1509 if (coredev->mode == DEVICE_MODE_DVBT_BDA)
1510 phdr->msg_dst_id = DVBT_BDA_CONTROL_MSG_ID;
1511 }
1512
1513
1514 client = smscore_find_client(coredev, phdr->msg_type, phdr->msg_dst_id);
1515
1516 /* If no client registered for type & id,
1517 * check for control client where type is not registered */
1518 if (client)
1519 rc = client->onresponse_handler(client->context, cb);
1520
1521 if (rc < 0) {
1522 switch (phdr->msg_type) {
1523 case MSG_SMS_ISDBT_TUNE_RES:
1524 break;
1525 case MSG_SMS_RF_TUNE_RES:
1526 break;
1527 case MSG_SMS_SIGNAL_DETECTED_IND:
1528 break;
1529 case MSG_SMS_NO_SIGNAL_IND:
1530 break;
1531 case MSG_SMS_SPI_INT_LINE_SET_RES:
1532 break;
1533 case MSG_SMS_INTERFACE_LOCK_IND:
1534 break;
1535 case MSG_SMS_INTERFACE_UNLOCK_IND:
1536 break;
1537 case MSG_SMS_GET_VERSION_EX_RES:
1538 {
1539 struct sms_version_res *ver =
1540 (struct sms_version_res *) phdr;
1541 pr_debug("Firmware id %d prots 0x%x ver %d.%d\n",
1542 ver->firmware_id, ver->supported_protocols,
1543 ver->rom_ver_major, ver->rom_ver_minor);
1544
1545 coredev->mode = ver->firmware_id == 255 ?
1546 DEVICE_MODE_NONE : ver->firmware_id;
1547 coredev->modes_supported = ver->supported_protocols;
1548 coredev->fw_version = ver->rom_ver_major << 8 |
1549 ver->rom_ver_minor;
1550
1551 complete(&coredev->version_ex_done);
1552 break;
1553 }
1554 case MSG_SMS_INIT_DEVICE_RES:
1555 complete(&coredev->init_device_done);
1556 break;
1557 case MSG_SW_RELOAD_START_RES:
1558 complete(&coredev->reload_start_done);
1559 break;
1560 case MSG_SMS_DATA_VALIDITY_RES:
1561 {
1562 struct sms_msg_data *validity = (struct sms_msg_data *) phdr;
1563
1564 pr_debug("MSG_SMS_DATA_VALIDITY_RES, checksum = 0x%x\n",
1565 validity->msg_data[0]);
1566 complete(&coredev->data_validity_done);
1567 break;
1568 }
1569 case MSG_SMS_DATA_DOWNLOAD_RES:
1570 complete(&coredev->data_download_done);
1571 break;
1572 case MSG_SW_RELOAD_EXEC_RES:
1573 break;
1574 case MSG_SMS_SWDOWNLOAD_TRIGGER_RES:
1575 complete(&coredev->trigger_done);
1576 break;
1577 case MSG_SMS_SLEEP_RESUME_COMP_IND:
1578 complete(&coredev->resume_done);
1579 break;
1580 case MSG_SMS_GPIO_CONFIG_EX_RES:
1581 complete(&coredev->gpio_configuration_done);
1582 break;
1583 case MSG_SMS_GPIO_SET_LEVEL_RES:
1584 complete(&coredev->gpio_set_level_done);
1585 break;
1586 case MSG_SMS_GPIO_GET_LEVEL_RES:
1587 {
1588 u32 *msgdata = (u32 *) phdr;
1589 coredev->gpio_get_res = msgdata[1];
1590 pr_debug("gpio level %d\n",
1591 coredev->gpio_get_res);
1592 complete(&coredev->gpio_get_level_done);
1593 break;
1594 }
1595 case MSG_SMS_START_IR_RES:
1596 complete(&coredev->ir_init_done);
1597 break;
1598 case MSG_SMS_IR_SAMPLES_IND:
1599 sms_ir_event(coredev,
1600 (const char *)
1601 ((char *)phdr
1602 + sizeof(struct sms_msg_hdr)),
1603 (int)phdr->msg_length
1604 - sizeof(struct sms_msg_hdr));
1605 break;
1606
1607 case MSG_SMS_DVBT_BDA_DATA:
1608 /*
1609 * It can be received here, if the frontend is
1610 * tuned into a valid channel and the proper firmware
1611 * is loaded. That happens when the module got removed
1612 * and re-inserted, without powering the device off
1613 */
1614 break;
1615
1616 default:
1617 pr_debug("message %s(%d) not handled.\n",
1618 smscore_translate_msg(phdr->msg_type),
1619 phdr->msg_type);
1620 break;
1621 }
1622 smscore_putbuffer(coredev, cb);
1623 }
1624 }
1625 EXPORT_SYMBOL_GPL(smscore_onresponse);
1626
1627 /*
1628 * return pointer to next free buffer descriptor from core pool
1629 *
1630 * @param coredev pointer to a coredev object returned by
1631 * smscore_register_device
1632 *
1633 * return: pointer to descriptor on success, NULL on error.
1634 */
1635
get_entry(struct smscore_device_t * coredev)1636 static struct smscore_buffer_t *get_entry(struct smscore_device_t *coredev)
1637 {
1638 struct smscore_buffer_t *cb = NULL;
1639 unsigned long flags;
1640
1641 spin_lock_irqsave(&coredev->bufferslock, flags);
1642 if (!list_empty(&coredev->buffers)) {
1643 cb = (struct smscore_buffer_t *) coredev->buffers.next;
1644 list_del(&cb->entry);
1645 }
1646 spin_unlock_irqrestore(&coredev->bufferslock, flags);
1647 return cb;
1648 }
1649
smscore_getbuffer(struct smscore_device_t * coredev)1650 struct smscore_buffer_t *smscore_getbuffer(struct smscore_device_t *coredev)
1651 {
1652 struct smscore_buffer_t *cb = NULL;
1653
1654 wait_event(coredev->buffer_mng_waitq, (cb = get_entry(coredev)));
1655
1656 return cb;
1657 }
1658 EXPORT_SYMBOL_GPL(smscore_getbuffer);
1659
1660 /*
1661 * return buffer descriptor to a pool
1662 *
1663 * @param coredev pointer to a coredev object returned by
1664 * smscore_register_device
1665 * @param cb pointer buffer descriptor
1666 *
1667 */
smscore_putbuffer(struct smscore_device_t * coredev,struct smscore_buffer_t * cb)1668 void smscore_putbuffer(struct smscore_device_t *coredev,
1669 struct smscore_buffer_t *cb) {
1670 wake_up_interruptible(&coredev->buffer_mng_waitq);
1671 list_add_locked(&cb->entry, &coredev->buffers, &coredev->bufferslock);
1672 }
1673 EXPORT_SYMBOL_GPL(smscore_putbuffer);
1674
smscore_validate_client(struct smscore_device_t * coredev,struct smscore_client_t * client,int data_type,int id)1675 static int smscore_validate_client(struct smscore_device_t *coredev,
1676 struct smscore_client_t *client,
1677 int data_type, int id)
1678 {
1679 struct smscore_idlist_t *listentry;
1680 struct smscore_client_t *registered_client;
1681
1682 if (!client) {
1683 pr_err("bad parameter.\n");
1684 return -EINVAL;
1685 }
1686 registered_client = smscore_find_client(coredev, data_type, id);
1687 if (registered_client == client)
1688 return 0;
1689
1690 if (registered_client) {
1691 pr_err("The msg ID already registered to another client.\n");
1692 return -EEXIST;
1693 }
1694 listentry = kzalloc(sizeof(*listentry), GFP_KERNEL);
1695 if (!listentry)
1696 return -ENOMEM;
1697
1698 listentry->id = id;
1699 listentry->data_type = data_type;
1700 list_add_locked(&listentry->entry, &client->idlist,
1701 &coredev->clientslock);
1702 return 0;
1703 }
1704
1705 /*
1706 * creates smsclient object, check that id is taken by another client
1707 *
1708 * @param coredev pointer to a coredev object from clients hotplug
1709 * @param initial_id all messages with this id would be sent to this client
1710 * @param data_type all messages of this type would be sent to this client
1711 * @param onresponse_handler client handler that is called to
1712 * process incoming messages
1713 * @param onremove_handler client handler that is called when device is removed
1714 * @param context client-specific context
1715 * @param client pointer to a value that receives created smsclient object
1716 *
1717 * return: 0 on success, <0 on error.
1718 */
smscore_register_client(struct smscore_device_t * coredev,struct smsclient_params_t * params,struct smscore_client_t ** client)1719 int smscore_register_client(struct smscore_device_t *coredev,
1720 struct smsclient_params_t *params,
1721 struct smscore_client_t **client)
1722 {
1723 struct smscore_client_t *newclient;
1724 /* check that no other channel with same parameters exists */
1725 if (smscore_find_client(coredev, params->data_type,
1726 params->initial_id)) {
1727 pr_err("Client already exist.\n");
1728 return -EEXIST;
1729 }
1730
1731 newclient = kzalloc(sizeof(*newclient), GFP_KERNEL);
1732 if (!newclient)
1733 return -ENOMEM;
1734
1735 INIT_LIST_HEAD(&newclient->idlist);
1736 newclient->coredev = coredev;
1737 newclient->onresponse_handler = params->onresponse_handler;
1738 newclient->onremove_handler = params->onremove_handler;
1739 newclient->context = params->context;
1740 list_add_locked(&newclient->entry, &coredev->clients,
1741 &coredev->clientslock);
1742 smscore_validate_client(coredev, newclient, params->data_type,
1743 params->initial_id);
1744 *client = newclient;
1745 pr_debug("%p %d %d\n", params->context, params->data_type,
1746 params->initial_id);
1747
1748 return 0;
1749 }
1750 EXPORT_SYMBOL_GPL(smscore_register_client);
1751
1752 /*
1753 * frees smsclient object and all subclients associated with it
1754 *
1755 * @param client pointer to smsclient object returned by
1756 * smscore_register_client
1757 *
1758 */
smscore_unregister_client(struct smscore_client_t * client)1759 void smscore_unregister_client(struct smscore_client_t *client)
1760 {
1761 struct smscore_device_t *coredev = client->coredev;
1762 unsigned long flags;
1763
1764 spin_lock_irqsave(&coredev->clientslock, flags);
1765
1766
1767 while (!list_empty(&client->idlist)) {
1768 struct smscore_idlist_t *identry =
1769 (struct smscore_idlist_t *) client->idlist.next;
1770 list_del(&identry->entry);
1771 kfree(identry);
1772 }
1773
1774 pr_debug("%p\n", client->context);
1775
1776 list_del(&client->entry);
1777 kfree(client);
1778
1779 spin_unlock_irqrestore(&coredev->clientslock, flags);
1780 }
1781 EXPORT_SYMBOL_GPL(smscore_unregister_client);
1782
1783 /*
1784 * verifies that source id is not taken by another client,
1785 * calls device handler to send requests to the device
1786 *
1787 * @param client pointer to smsclient object returned by
1788 * smscore_register_client
1789 * @param buffer pointer to a request buffer
1790 * @param size size (in bytes) of request buffer
1791 *
1792 * return: 0 on success, <0 on error.
1793 */
smsclient_sendrequest(struct smscore_client_t * client,void * buffer,size_t size)1794 int smsclient_sendrequest(struct smscore_client_t *client,
1795 void *buffer, size_t size)
1796 {
1797 struct smscore_device_t *coredev;
1798 struct sms_msg_hdr *phdr = (struct sms_msg_hdr *) buffer;
1799 int rc;
1800
1801 if (!client) {
1802 pr_err("Got NULL client\n");
1803 return -EINVAL;
1804 }
1805
1806 coredev = client->coredev;
1807
1808 /* check that no other channel with same id exists */
1809 if (!coredev) {
1810 pr_err("Got NULL coredev\n");
1811 return -EINVAL;
1812 }
1813
1814 rc = smscore_validate_client(client->coredev, client, 0,
1815 phdr->msg_src_id);
1816 if (rc < 0)
1817 return rc;
1818
1819 return coredev->sendrequest_handler(coredev->context, buffer, size);
1820 }
1821 EXPORT_SYMBOL_GPL(smsclient_sendrequest);
1822
1823
1824 /* old GPIO managements implementation */
smscore_configure_gpio(struct smscore_device_t * coredev,u32 pin,struct smscore_config_gpio * pinconfig)1825 int smscore_configure_gpio(struct smscore_device_t *coredev, u32 pin,
1826 struct smscore_config_gpio *pinconfig)
1827 {
1828 struct {
1829 struct sms_msg_hdr hdr;
1830 u32 data[6];
1831 } msg;
1832
1833 if (coredev->device_flags & SMS_DEVICE_FAMILY2) {
1834 msg.hdr.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
1835 msg.hdr.msg_dst_id = HIF_TASK;
1836 msg.hdr.msg_flags = 0;
1837 msg.hdr.msg_type = MSG_SMS_GPIO_CONFIG_EX_REQ;
1838 msg.hdr.msg_length = sizeof(msg);
1839
1840 msg.data[0] = pin;
1841 msg.data[1] = pinconfig->pullupdown;
1842
1843 /* Convert slew rate for Nova: Fast(0) = 3 / Slow(1) = 0; */
1844 msg.data[2] = pinconfig->outputslewrate == 0 ? 3 : 0;
1845
1846 switch (pinconfig->outputdriving) {
1847 case SMS_GPIO_OUTPUTDRIVING_S_16mA:
1848 msg.data[3] = 7; /* Nova - 16mA */
1849 break;
1850 case SMS_GPIO_OUTPUTDRIVING_S_12mA:
1851 msg.data[3] = 5; /* Nova - 11mA */
1852 break;
1853 case SMS_GPIO_OUTPUTDRIVING_S_8mA:
1854 msg.data[3] = 3; /* Nova - 7mA */
1855 break;
1856 case SMS_GPIO_OUTPUTDRIVING_S_4mA:
1857 default:
1858 msg.data[3] = 2; /* Nova - 4mA */
1859 break;
1860 }
1861
1862 msg.data[4] = pinconfig->direction;
1863 msg.data[5] = 0;
1864 } else /* TODO: SMS_DEVICE_FAMILY1 */
1865 return -EINVAL;
1866
1867 return coredev->sendrequest_handler(coredev->context,
1868 &msg, sizeof(msg));
1869 }
1870
smscore_set_gpio(struct smscore_device_t * coredev,u32 pin,int level)1871 int smscore_set_gpio(struct smscore_device_t *coredev, u32 pin, int level)
1872 {
1873 struct {
1874 struct sms_msg_hdr hdr;
1875 u32 data[3];
1876 } msg;
1877
1878 if (pin > MAX_GPIO_PIN_NUMBER)
1879 return -EINVAL;
1880
1881 msg.hdr.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
1882 msg.hdr.msg_dst_id = HIF_TASK;
1883 msg.hdr.msg_flags = 0;
1884 msg.hdr.msg_type = MSG_SMS_GPIO_SET_LEVEL_REQ;
1885 msg.hdr.msg_length = sizeof(msg);
1886
1887 msg.data[0] = pin;
1888 msg.data[1] = level ? 1 : 0;
1889 msg.data[2] = 0;
1890
1891 return coredev->sendrequest_handler(coredev->context,
1892 &msg, sizeof(msg));
1893 }
1894
1895 /* new GPIO management implementation */
get_gpio_pin_params(u32 pin_num,u32 * p_translatedpin_num,u32 * p_group_num,u32 * p_group_cfg)1896 static int get_gpio_pin_params(u32 pin_num, u32 *p_translatedpin_num,
1897 u32 *p_group_num, u32 *p_group_cfg) {
1898
1899 *p_group_cfg = 1;
1900
1901 if (pin_num <= 1) {
1902 *p_translatedpin_num = 0;
1903 *p_group_num = 9;
1904 *p_group_cfg = 2;
1905 } else if (pin_num >= 2 && pin_num <= 6) {
1906 *p_translatedpin_num = 2;
1907 *p_group_num = 0;
1908 *p_group_cfg = 2;
1909 } else if (pin_num >= 7 && pin_num <= 11) {
1910 *p_translatedpin_num = 7;
1911 *p_group_num = 1;
1912 } else if (pin_num >= 12 && pin_num <= 15) {
1913 *p_translatedpin_num = 12;
1914 *p_group_num = 2;
1915 *p_group_cfg = 3;
1916 } else if (pin_num == 16) {
1917 *p_translatedpin_num = 16;
1918 *p_group_num = 23;
1919 } else if (pin_num >= 17 && pin_num <= 24) {
1920 *p_translatedpin_num = 17;
1921 *p_group_num = 3;
1922 } else if (pin_num == 25) {
1923 *p_translatedpin_num = 25;
1924 *p_group_num = 6;
1925 } else if (pin_num >= 26 && pin_num <= 28) {
1926 *p_translatedpin_num = 26;
1927 *p_group_num = 4;
1928 } else if (pin_num == 29) {
1929 *p_translatedpin_num = 29;
1930 *p_group_num = 5;
1931 *p_group_cfg = 2;
1932 } else if (pin_num == 30) {
1933 *p_translatedpin_num = 30;
1934 *p_group_num = 8;
1935 } else if (pin_num == 31) {
1936 *p_translatedpin_num = 31;
1937 *p_group_num = 17;
1938 } else
1939 return -1;
1940
1941 *p_group_cfg <<= 24;
1942
1943 return 0;
1944 }
1945
smscore_gpio_configure(struct smscore_device_t * coredev,u8 pin_num,struct smscore_config_gpio * p_gpio_config)1946 int smscore_gpio_configure(struct smscore_device_t *coredev, u8 pin_num,
1947 struct smscore_config_gpio *p_gpio_config) {
1948
1949 u32 total_len;
1950 u32 translatedpin_num = 0;
1951 u32 group_num = 0;
1952 u32 electric_char;
1953 u32 group_cfg;
1954 void *buffer;
1955 int rc;
1956
1957 struct set_gpio_msg {
1958 struct sms_msg_hdr x_msg_header;
1959 u32 msg_data[6];
1960 } *p_msg;
1961
1962
1963 if (pin_num > MAX_GPIO_PIN_NUMBER)
1964 return -EINVAL;
1965
1966 if (!p_gpio_config)
1967 return -EINVAL;
1968
1969 total_len = sizeof(struct sms_msg_hdr) + (sizeof(u32) * 6);
1970
1971 buffer = kmalloc(total_len + SMS_DMA_ALIGNMENT,
1972 GFP_KERNEL | coredev->gfp_buf_flags);
1973 if (!buffer)
1974 return -ENOMEM;
1975
1976 p_msg = (struct set_gpio_msg *) SMS_ALIGN_ADDRESS(buffer);
1977
1978 p_msg->x_msg_header.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
1979 p_msg->x_msg_header.msg_dst_id = HIF_TASK;
1980 p_msg->x_msg_header.msg_flags = 0;
1981 p_msg->x_msg_header.msg_length = (u16) total_len;
1982 p_msg->msg_data[0] = pin_num;
1983
1984 if (!(coredev->device_flags & SMS_DEVICE_FAMILY2)) {
1985 p_msg->x_msg_header.msg_type = MSG_SMS_GPIO_CONFIG_REQ;
1986 if (get_gpio_pin_params(pin_num, &translatedpin_num, &group_num,
1987 &group_cfg) != 0) {
1988 rc = -EINVAL;
1989 goto free;
1990 }
1991
1992 p_msg->msg_data[1] = translatedpin_num;
1993 p_msg->msg_data[2] = group_num;
1994 electric_char = (p_gpio_config->pullupdown)
1995 | (p_gpio_config->inputcharacteristics << 2)
1996 | (p_gpio_config->outputslewrate << 3)
1997 | (p_gpio_config->outputdriving << 4);
1998 p_msg->msg_data[3] = electric_char;
1999 p_msg->msg_data[4] = p_gpio_config->direction;
2000 p_msg->msg_data[5] = group_cfg;
2001 } else {
2002 p_msg->x_msg_header.msg_type = MSG_SMS_GPIO_CONFIG_EX_REQ;
2003 p_msg->msg_data[1] = p_gpio_config->pullupdown;
2004 p_msg->msg_data[2] = p_gpio_config->outputslewrate;
2005 p_msg->msg_data[3] = p_gpio_config->outputdriving;
2006 p_msg->msg_data[4] = p_gpio_config->direction;
2007 p_msg->msg_data[5] = 0;
2008 }
2009
2010 rc = smscore_sendrequest_and_wait(coredev, p_msg, total_len,
2011 &coredev->gpio_configuration_done);
2012
2013 if (rc != 0) {
2014 if (rc == -ETIME)
2015 pr_err("smscore_gpio_configure timeout\n");
2016 else
2017 pr_err("smscore_gpio_configure error\n");
2018 }
2019 free:
2020 kfree(buffer);
2021
2022 return rc;
2023 }
2024
smscore_gpio_set_level(struct smscore_device_t * coredev,u8 pin_num,u8 new_level)2025 int smscore_gpio_set_level(struct smscore_device_t *coredev, u8 pin_num,
2026 u8 new_level) {
2027
2028 u32 total_len;
2029 int rc;
2030 void *buffer;
2031
2032 struct set_gpio_msg {
2033 struct sms_msg_hdr x_msg_header;
2034 u32 msg_data[3]; /* keep it 3 ! */
2035 } *p_msg;
2036
2037 if ((new_level > 1) || (pin_num > MAX_GPIO_PIN_NUMBER))
2038 return -EINVAL;
2039
2040 total_len = sizeof(struct sms_msg_hdr) +
2041 (3 * sizeof(u32)); /* keep it 3 ! */
2042
2043 buffer = kmalloc(total_len + SMS_DMA_ALIGNMENT,
2044 GFP_KERNEL | coredev->gfp_buf_flags);
2045 if (!buffer)
2046 return -ENOMEM;
2047
2048 p_msg = (struct set_gpio_msg *) SMS_ALIGN_ADDRESS(buffer);
2049
2050 p_msg->x_msg_header.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
2051 p_msg->x_msg_header.msg_dst_id = HIF_TASK;
2052 p_msg->x_msg_header.msg_flags = 0;
2053 p_msg->x_msg_header.msg_type = MSG_SMS_GPIO_SET_LEVEL_REQ;
2054 p_msg->x_msg_header.msg_length = (u16) total_len;
2055 p_msg->msg_data[0] = pin_num;
2056 p_msg->msg_data[1] = new_level;
2057
2058 /* Send message to SMS */
2059 rc = smscore_sendrequest_and_wait(coredev, p_msg, total_len,
2060 &coredev->gpio_set_level_done);
2061
2062 if (rc != 0) {
2063 if (rc == -ETIME)
2064 pr_err("smscore_gpio_set_level timeout\n");
2065 else
2066 pr_err("smscore_gpio_set_level error\n");
2067 }
2068 kfree(buffer);
2069
2070 return rc;
2071 }
2072
smscore_gpio_get_level(struct smscore_device_t * coredev,u8 pin_num,u8 * level)2073 int smscore_gpio_get_level(struct smscore_device_t *coredev, u8 pin_num,
2074 u8 *level) {
2075
2076 u32 total_len;
2077 int rc;
2078 void *buffer;
2079
2080 struct set_gpio_msg {
2081 struct sms_msg_hdr x_msg_header;
2082 u32 msg_data[2];
2083 } *p_msg;
2084
2085
2086 if (pin_num > MAX_GPIO_PIN_NUMBER)
2087 return -EINVAL;
2088
2089 total_len = sizeof(struct sms_msg_hdr) + (2 * sizeof(u32));
2090
2091 buffer = kmalloc(total_len + SMS_DMA_ALIGNMENT,
2092 GFP_KERNEL | coredev->gfp_buf_flags);
2093 if (!buffer)
2094 return -ENOMEM;
2095
2096 p_msg = (struct set_gpio_msg *) SMS_ALIGN_ADDRESS(buffer);
2097
2098 p_msg->x_msg_header.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
2099 p_msg->x_msg_header.msg_dst_id = HIF_TASK;
2100 p_msg->x_msg_header.msg_flags = 0;
2101 p_msg->x_msg_header.msg_type = MSG_SMS_GPIO_GET_LEVEL_REQ;
2102 p_msg->x_msg_header.msg_length = (u16) total_len;
2103 p_msg->msg_data[0] = pin_num;
2104 p_msg->msg_data[1] = 0;
2105
2106 /* Send message to SMS */
2107 rc = smscore_sendrequest_and_wait(coredev, p_msg, total_len,
2108 &coredev->gpio_get_level_done);
2109
2110 if (rc != 0) {
2111 if (rc == -ETIME)
2112 pr_err("smscore_gpio_get_level timeout\n");
2113 else
2114 pr_err("smscore_gpio_get_level error\n");
2115 }
2116 kfree(buffer);
2117
2118 /* Its a race between other gpio_get_level() and the copy of the single
2119 * global 'coredev->gpio_get_res' to the function's variable 'level'
2120 */
2121 *level = coredev->gpio_get_res;
2122
2123 return rc;
2124 }
2125
smscore_module_init(void)2126 static int __init smscore_module_init(void)
2127 {
2128 INIT_LIST_HEAD(&g_smscore_notifyees);
2129 INIT_LIST_HEAD(&g_smscore_devices);
2130 kmutex_init(&g_smscore_deviceslock);
2131
2132 INIT_LIST_HEAD(&g_smscore_registry);
2133 kmutex_init(&g_smscore_registrylock);
2134
2135 return 0;
2136 }
2137
smscore_module_exit(void)2138 static void __exit smscore_module_exit(void)
2139 {
2140 kmutex_lock(&g_smscore_deviceslock);
2141 while (!list_empty(&g_smscore_notifyees)) {
2142 struct smscore_device_notifyee_t *notifyee =
2143 (struct smscore_device_notifyee_t *)
2144 g_smscore_notifyees.next;
2145
2146 list_del(¬ifyee->entry);
2147 kfree(notifyee);
2148 }
2149 kmutex_unlock(&g_smscore_deviceslock);
2150
2151 kmutex_lock(&g_smscore_registrylock);
2152 while (!list_empty(&g_smscore_registry)) {
2153 struct smscore_registry_entry_t *entry =
2154 (struct smscore_registry_entry_t *)
2155 g_smscore_registry.next;
2156
2157 list_del(&entry->entry);
2158 kfree(entry);
2159 }
2160 kmutex_unlock(&g_smscore_registrylock);
2161
2162 pr_debug("\n");
2163 }
2164
2165 module_init(smscore_module_init);
2166 module_exit(smscore_module_exit);
2167
2168 MODULE_DESCRIPTION("Siano MDTV Core module");
2169 MODULE_AUTHOR("Siano Mobile Silicon, Inc. (uris@siano-ms.com)");
2170 MODULE_LICENSE("GPL");
2171
2172 /* This should match what's defined at smscoreapi.h */
2173 MODULE_FIRMWARE(SMS_FW_ATSC_DENVER);
2174 MODULE_FIRMWARE(SMS_FW_CMMB_MING_APP);
2175 MODULE_FIRMWARE(SMS_FW_CMMB_VEGA_12MHZ);
2176 MODULE_FIRMWARE(SMS_FW_CMMB_VENICE_12MHZ);
2177 MODULE_FIRMWARE(SMS_FW_DVBH_RIO);
2178 MODULE_FIRMWARE(SMS_FW_DVB_NOVA_12MHZ_B0);
2179 MODULE_FIRMWARE(SMS_FW_DVB_NOVA_12MHZ);
2180 MODULE_FIRMWARE(SMS_FW_DVB_RIO);
2181 MODULE_FIRMWARE(SMS_FW_FM_RADIO);
2182 MODULE_FIRMWARE(SMS_FW_FM_RADIO_RIO);
2183 MODULE_FIRMWARE(SMS_FW_DVBT_HCW_55XXX);
2184 MODULE_FIRMWARE(SMS_FW_ISDBT_HCW_55XXX);
2185 MODULE_FIRMWARE(SMS_FW_ISDBT_NOVA_12MHZ_B0);
2186 MODULE_FIRMWARE(SMS_FW_ISDBT_NOVA_12MHZ);
2187 MODULE_FIRMWARE(SMS_FW_ISDBT_PELE);
2188 MODULE_FIRMWARE(SMS_FW_ISDBT_RIO);
2189 MODULE_FIRMWARE(SMS_FW_DVBT_NOVA_A);
2190 MODULE_FIRMWARE(SMS_FW_DVBT_NOVA_B);
2191 MODULE_FIRMWARE(SMS_FW_DVBT_STELLAR);
2192 MODULE_FIRMWARE(SMS_FW_TDMB_DENVER);
2193 MODULE_FIRMWARE(SMS_FW_TDMB_NOVA_12MHZ_B0);
2194 MODULE_FIRMWARE(SMS_FW_TDMB_NOVA_12MHZ);
2195