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