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