[media] siano: get rid of CammelCase from smscoreapi.h
[deliverable/linux.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 39#include "smsir.h"
2e5c1ec8 40
0d02efe4 41static int sms_dbg;
b9391f41 42module_param_named(debug, sms_dbg, int, 0644);
f14d56a9
MK
43MODULE_PARM_DESC(debug, "set debug level (info=1, adv=2 (or-able))");
44
18245e18 45struct smscore_device_notifyee_t {
2e5c1ec8
MK
46 struct list_head entry;
47 hotplug_t hotplug;
18245e18 48};
2e5c1ec8 49
18245e18 50struct smscore_idlist_t {
f17407a8
MK
51 struct list_head entry;
52 int id;
53 int data_type;
18245e18 54};
f17407a8 55
18245e18 56struct smscore_client_t {
2e5c1ec8 57 struct list_head entry;
18245e18 58 struct smscore_device_t *coredev;
2e5c1ec8 59 void *context;
f17407a8 60 struct list_head idlist;
2e5c1ec8
MK
61 onresponse_t onresponse_handler;
62 onremove_t onremove_handler;
18245e18 63};
2e5c1ec8 64
4c3bdb5e
MCC
65static 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",
385};
386
387char *smscore_translate_msg(enum msg_types msgtype)
388{
389 int i = msgtype - MSG_TYPE_BASE_VAL;
390 char *msg;
391
392 if (i < 0 || i > ARRAY_SIZE(siano_msgs))
393 return "Unknown msg type";
394
395 msg = siano_msgs[i];
396
397 if (!*msg)
398 return "Unknown msg type";
399
400 return msg;
401}
402EXPORT_SYMBOL_GPL(smscore_translate_msg);
403
1c11d546
MK
404void smscore_set_board_id(struct smscore_device_t *core, int id)
405{
406 core->board_id = id;
407}
408
7b29e10d
MK
409int smscore_led_state(struct smscore_device_t *core, int led)
410{
411 if (led >= 0)
412 core->led_state = led;
413 return core->led_state;
414}
a0beec8f 415EXPORT_SYMBOL_GPL(smscore_set_board_id);
7b29e10d 416
1c11d546
MK
417int smscore_get_board_id(struct smscore_device_t *core)
418{
419 return core->board_id;
420}
a0beec8f 421EXPORT_SYMBOL_GPL(smscore_get_board_id);
1c11d546 422
18245e18 423struct smscore_registry_entry_t {
2e5c1ec8
MK
424 struct list_head entry;
425 char devpath[32];
426 int mode;
18245e18
MK
427 enum sms_device_type_st type;
428};
2e5c1ec8 429
c5e0bd1a
AB
430static struct list_head g_smscore_notifyees;
431static struct list_head g_smscore_devices;
432static struct mutex g_smscore_deviceslock;
2e5c1ec8 433
c5e0bd1a
AB
434static struct list_head g_smscore_registry;
435static struct mutex g_smscore_registrylock;
2e5c1ec8 436
9711a8a6 437static int default_mode = DEVICE_MODE_NONE;
f17407a8 438
2e5c1ec8
MK
439module_param(default_mode, int, 0644);
440MODULE_PARM_DESC(default_mode, "default firmware id (device mode)");
441
18245e18 442static struct smscore_registry_entry_t *smscore_find_registry(char *devpath)
2e5c1ec8 443{
18245e18 444 struct smscore_registry_entry_t *entry;
2e5c1ec8
MK
445 struct list_head *next;
446
447 kmutex_lock(&g_smscore_registrylock);
82237416
MK
448 for (next = g_smscore_registry.next;
449 next != &g_smscore_registry;
450 next = next->next) {
18245e18 451 entry = (struct smscore_registry_entry_t *) next;
82237416 452 if (!strcmp(entry->devpath, devpath)) {
2e5c1ec8 453 kmutex_unlock(&g_smscore_registrylock);
f17407a8 454 return entry;
2e5c1ec8
MK
455 }
456 }
806ec0fb 457 entry = kmalloc(sizeof(struct smscore_registry_entry_t), GFP_KERNEL);
82237416 458 if (entry) {
2e5c1ec8
MK
459 entry->mode = default_mode;
460 strcpy(entry->devpath, devpath);
2e5c1ec8 461 list_add(&entry->entry, &g_smscore_registry);
82237416 462 } else
a0c0abcb 463 sms_err("failed to create smscore_registry.");
2e5c1ec8 464 kmutex_unlock(&g_smscore_registrylock);
f17407a8
MK
465 return entry;
466}
2e5c1ec8 467
82237416 468int smscore_registry_getmode(char *devpath)
f17407a8 469{
18245e18 470 struct smscore_registry_entry_t *entry;
f17407a8 471
82237416
MK
472 entry = smscore_find_registry(devpath);
473 if (entry)
f17407a8 474 return entry->mode;
f17407a8 475 else
a0c0abcb 476 sms_err("No registry found.");
82237416 477
2e5c1ec8
MK
478 return default_mode;
479}
a0beec8f 480EXPORT_SYMBOL_GPL(smscore_registry_getmode);
2e5c1ec8 481
0c071f37 482static enum sms_device_type_st smscore_registry_gettype(char *devpath)
2e5c1ec8 483{
18245e18 484 struct smscore_registry_entry_t *entry;
2e5c1ec8 485
82237416
MK
486 entry = smscore_find_registry(devpath);
487 if (entry)
f17407a8 488 return entry->type;
f17407a8 489 else
a0c0abcb 490 sms_err("No registry found.");
82237416 491
e5d218ee 492 return -EINVAL;
f17407a8 493}
2e5c1ec8 494
e5d218ee 495static void smscore_registry_setmode(char *devpath, int mode)
82237416 496{
18245e18 497 struct smscore_registry_entry_t *entry;
2e5c1ec8 498
82237416
MK
499 entry = smscore_find_registry(devpath);
500 if (entry)
501 entry->mode = mode;
f17407a8 502 else
a0c0abcb 503 sms_err("No registry found.");
82237416 504}
2e5c1ec8 505
0c071f37
MK
506static void smscore_registry_settype(char *devpath,
507 enum sms_device_type_st type)
f17407a8 508{
18245e18 509 struct smscore_registry_entry_t *entry;
f17407a8 510
82237416
MK
511 entry = smscore_find_registry(devpath);
512 if (entry)
f17407a8 513 entry->type = type;
f17407a8 514 else
a0c0abcb 515 sms_err("No registry found.");
2e5c1ec8
MK
516}
517
518
0c071f37
MK
519static void list_add_locked(struct list_head *new, struct list_head *head,
520 spinlock_t *lock)
2e5c1ec8
MK
521{
522 unsigned long flags;
523
524 spin_lock_irqsave(lock, flags);
525
526 list_add(new, head);
527
528 spin_unlock_irqrestore(lock, flags);
529}
530
531/**
532 * register a client callback that called when device plugged in/unplugged
533 * NOTE: if devices exist callback is called immediately for each device
534 *
535 * @param hotplug callback
536 *
537 * @return 0 on success, <0 on error.
538 */
539int smscore_register_hotplug(hotplug_t hotplug)
540{
18245e18 541 struct smscore_device_notifyee_t *notifyee;
2e5c1ec8
MK
542 struct list_head *next, *first;
543 int rc = 0;
544
545 kmutex_lock(&g_smscore_deviceslock);
546
18245e18
MK
547 notifyee = kmalloc(sizeof(struct smscore_device_notifyee_t),
548 GFP_KERNEL);
82237416
MK
549 if (notifyee) {
550 /* now notify callback about existing devices */
2e5c1ec8 551 first = &g_smscore_devices;
82237416
MK
552 for (next = first->next;
553 next != first && !rc;
554 next = next->next) {
18245e18
MK
555 struct smscore_device_t *coredev =
556 (struct smscore_device_t *) next;
2e5c1ec8
MK
557 rc = hotplug(coredev, coredev->device, 1);
558 }
559
82237416 560 if (rc >= 0) {
2e5c1ec8
MK
561 notifyee->hotplug = hotplug;
562 list_add(&notifyee->entry, &g_smscore_notifyees);
82237416 563 } else
2e5c1ec8 564 kfree(notifyee);
82237416 565 } else
2e5c1ec8
MK
566 rc = -ENOMEM;
567
568 kmutex_unlock(&g_smscore_deviceslock);
569
570 return rc;
571}
a0beec8f 572EXPORT_SYMBOL_GPL(smscore_register_hotplug);
2e5c1ec8
MK
573
574/**
575 * unregister a client callback that called when device plugged in/unplugged
576 *
577 * @param hotplug callback
578 *
579 */
580void smscore_unregister_hotplug(hotplug_t hotplug)
581{
582 struct list_head *next, *first;
583
584 kmutex_lock(&g_smscore_deviceslock);
585
586 first = &g_smscore_notifyees;
587
82237416 588 for (next = first->next; next != first;) {
18245e18
MK
589 struct smscore_device_notifyee_t *notifyee =
590 (struct smscore_device_notifyee_t *) next;
2e5c1ec8
MK
591 next = next->next;
592
82237416 593 if (notifyee->hotplug == hotplug) {
2e5c1ec8
MK
594 list_del(&notifyee->entry);
595 kfree(notifyee);
596 }
597 }
598
599 kmutex_unlock(&g_smscore_deviceslock);
600}
a0beec8f 601EXPORT_SYMBOL_GPL(smscore_unregister_hotplug);
2e5c1ec8 602
0c071f37 603static void smscore_notify_clients(struct smscore_device_t *coredev)
2e5c1ec8 604{
18245e18 605 struct smscore_client_t *client;
2e5c1ec8 606
82237416
MK
607 /* the client must call smscore_unregister_client from remove handler */
608 while (!list_empty(&coredev->clients)) {
18245e18 609 client = (struct smscore_client_t *) coredev->clients.next;
2e5c1ec8
MK
610 client->onremove_handler(client->context);
611 }
612}
613
0c071f37
MK
614static int smscore_notify_callbacks(struct smscore_device_t *coredev,
615 struct device *device, int arrival)
2e5c1ec8 616{
0208c15e 617 struct smscore_device_notifyee_t *elem;
2e5c1ec8
MK
618 int rc = 0;
619
82237416 620 /* note: must be called under g_deviceslock */
2e5c1ec8 621
0208c15e
JL
622 list_for_each_entry(elem, &g_smscore_notifyees, entry) {
623 rc = elem->hotplug(coredev, device, arrival);
2e5c1ec8
MK
624 if (rc < 0)
625 break;
626 }
627
628 return rc;
629}
630
0c071f37
MK
631static struct
632smscore_buffer_t *smscore_createbuffer(u8 *buffer, void *common_buffer,
a83ccdd6 633 dma_addr_t common_buffer_phys)
2e5c1ec8 634{
e5d218ee
MCC
635 struct smscore_buffer_t *cb;
636
637 cb = kzalloc(sizeof(struct smscore_buffer_t), GFP_KERNEL);
82237416 638 if (!cb) {
e5d218ee 639 sms_info("kzalloc(...) 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) {
e5d218ee
MCC
713 struct smscore_buffer_t *cb;
714
715 cb = smscore_createbuffer(buffer, dev->common_buffer,
716 dev->common_buffer_phys);
82237416 717 if (!cb) {
2e5c1ec8
MK
718 smscore_unregister_device(dev);
719 return -ENOMEM;
720 }
721
722 smscore_putbuffer(dev, cb);
723 }
724
a0c0abcb 725 sms_info("allocated %d buffers", dev->num_buffers);
2e5c1ec8
MK
726
727 dev->mode = DEVICE_MODE_NONE;
3ba92d0b 728 dev->board_id = SMS_BOARD_UNKNOWN;
2e5c1ec8
MK
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;
736
737 dev->device_flags = params->flags;
738 strcpy(dev->devpath, params->devpath);
739
82237416 740 smscore_registry_settype(dev->devpath, params->device_type);
f17407a8 741
82237416 742 /* add device to devices list */
2e5c1ec8
MK
743 kmutex_lock(&g_smscore_deviceslock);
744 list_add(&dev->entry, &g_smscore_devices);
745 kmutex_unlock(&g_smscore_deviceslock);
746
747 *coredev = dev;
748
a0c0abcb 749 sms_info("device %p created", dev);
2e5c1ec8
MK
750
751 return 0;
752}
a0beec8f 753EXPORT_SYMBOL_GPL(smscore_register_device);
2e5c1ec8 754
a804800a
US
755
756static int smscore_sendrequest_and_wait(struct smscore_device_t *coredev,
757 void *buffer, size_t size, struct completion *completion) {
018b0c6f
MCC
758 int rc;
759
760 if (completion == NULL)
761 return -EINVAL;
762 init_completion(completion);
763
764 rc = coredev->sendrequest_handler(coredev->context, buffer, size);
a804800a
US
765 if (rc < 0) {
766 sms_info("sendrequest returned error %d", rc);
767 return rc;
768 }
769
770 return wait_for_completion_timeout(completion,
771 msecs_to_jiffies(SMS_PROTOCOL_MAX_RAOUNDTRIP_MS)) ?
772 0 : -ETIME;
773}
774
775/**
776 * Starts & enables IR operations
777 *
778 * @return 0 on success, < 0 on error.
779 */
780static int smscore_init_ir(struct smscore_device_t *coredev)
781{
782 int ir_io;
783 int rc;
784 void *buffer;
785
d8b4b582 786 coredev->ir.dev = NULL;
a804800a
US
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);
791
792 if (rc != 0)
793 sms_err("Error initialization DTV IR sub-module");
794 else {
dfef84fc 795 buffer = kmalloc(sizeof(struct sms_msg_data2) +
a804800a
US
796 SMS_DMA_ALIGNMENT,
797 GFP_KERNEL | GFP_DMA);
798 if (buffer) {
dfef84fc
MCC
799 struct sms_msg_data2 *msg =
800 (struct sms_msg_data2 *)
a804800a
US
801 SMS_ALIGN_ADDRESS(buffer);
802
dfef84fc 803 SMS_INIT_MSG(&msg->x_msg_header,
a804800a 804 MSG_SMS_START_IR_REQ,
dfef84fc 805 sizeof(struct sms_msg_data2));
a804800a
US
806 msg->msgData[0] = coredev->ir.controller;
807 msg->msgData[1] = coredev->ir.timeout;
808
a804800a 809 rc = smscore_sendrequest_and_wait(coredev, msg,
dfef84fc 810 msg->x_msg_header. msg_length,
a804800a
US
811 &coredev->ir_init_done);
812
813 kfree(buffer);
814 } else
815 sms_err
816 ("Sending IR initialization message failed");
817 }
818 } else
819 sms_info("IR port has not been detected");
820
821 return 0;
822}
823
dfbf021c
MCC
824/**
825 * configures device features according to board configuration structure.
826 *
827 * @param coredev pointer to a coredev object returned by
828 * smscore_register_device
829 *
830 * @return 0 on success, <0 on error.
831 */
832int smscore_configure_board(struct smscore_device_t *coredev)
833{
834 struct sms_board *board;
835
836 board = sms_get_board(coredev->board_id);
837 if (!board) {
838 sms_err("no board configuration exist.");
839 return -EINVAL;
840 }
841
842 if (board->mtu) {
dfef84fc 843 struct sms_msg_data MtuMsg;
dfbf021c
MCC
844 sms_debug("set max transmit unit %d", board->mtu);
845
dfef84fc
MCC
846 MtuMsg.x_msg_header.msg_src_id = 0;
847 MtuMsg.x_msg_header.msg_dst_id = HIF_TASK;
848 MtuMsg.x_msg_header.msg_flags = 0;
849 MtuMsg.x_msg_header.msg_type = MSG_SMS_SET_MAX_TX_MSG_LEN_REQ;
850 MtuMsg.x_msg_header.msg_length = sizeof(MtuMsg);
dfbf021c
MCC
851 MtuMsg.msgData[0] = board->mtu;
852
dfbf021c
MCC
853 coredev->sendrequest_handler(coredev->context, &MtuMsg,
854 sizeof(MtuMsg));
855 }
856
857 if (board->crystal) {
dfef84fc 858 struct sms_msg_data CrysMsg;
dfbf021c
MCC
859 sms_debug("set crystal value %d", board->crystal);
860
dfef84fc 861 SMS_INIT_MSG(&CrysMsg.x_msg_header,
dfbf021c
MCC
862 MSG_SMS_NEW_CRYSTAL_REQ,
863 sizeof(CrysMsg));
864 CrysMsg.msgData[0] = board->crystal;
865
dfbf021c
MCC
866 coredev->sendrequest_handler(coredev->context, &CrysMsg,
867 sizeof(CrysMsg));
868 }
869
870 return 0;
871}
872
2e5c1ec8
MK
873/**
874 * sets initial device mode and notifies client hotplugs that device is ready
875 *
59bf6b8e
MK
876 * @param coredev pointer to a coredev object returned by
877 * smscore_register_device
2e5c1ec8
MK
878 *
879 * @return 0 on success, <0 on error.
880 */
18245e18 881int smscore_start_device(struct smscore_device_t *coredev)
2e5c1ec8 882{
9711a8a6
MCC
883 int rc;
884 int board_id = smscore_get_board_id(coredev);
885 int mode = smscore_registry_getmode(coredev->devpath);
886
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;
890
891 rc = smscore_set_device_mode(coredev, mode);
82237416 892 if (rc < 0) {
a0c0abcb 893 sms_info("set device mode faile , rc %d", rc);
2e5c1ec8 894 return rc;
f17407a8 895 }
dfbf021c
MCC
896 rc = smscore_configure_board(coredev);
897 if (rc < 0) {
898 sms_info("configure board failed , rc %d", rc);
899 return rc;
900 }
2e5c1ec8
MK
901
902 kmutex_lock(&g_smscore_deviceslock);
903
904 rc = smscore_notify_callbacks(coredev, coredev->device, 1);
a804800a 905 smscore_init_ir(coredev);
2e5c1ec8 906
a0c0abcb 907 sms_info("device %p started, rc %d", coredev, rc);
2e5c1ec8
MK
908
909 kmutex_unlock(&g_smscore_deviceslock);
910
911 return rc;
912}
a0beec8f 913EXPORT_SYMBOL_GPL(smscore_start_device);
2e5c1ec8 914
2e5c1ec8 915
0c071f37
MK
916static int smscore_load_firmware_family2(struct smscore_device_t *coredev,
917 void *buffer, size_t size)
2e5c1ec8 918{
dfef84fc
MCC
919 struct sms_firmware *firmware = (struct sms_firmware *) buffer;
920 struct sms_msg_data4 *msg;
018b0c6f
MCC
921 u32 mem_address, calc_checksum = 0;
922 u32 i, *ptr;
dfef84fc 923 u8 *payload = firmware->payload;
2e5c1ec8 924 int rc = 0;
dfef84fc
MCC
925 firmware->start_address = le32_to_cpu(firmware->start_address);
926 firmware->length = le32_to_cpu(firmware->length);
01abc0b0 927
dfef84fc 928 mem_address = firmware->start_address;
2e5c1ec8 929
a0c0abcb 930 sms_info("loading FW to addr 0x%x size %d",
dfef84fc 931 mem_address, firmware->length);
82237416 932 if (coredev->preload_handler) {
2e5c1ec8
MK
933 rc = coredev->preload_handler(coredev->context);
934 if (rc < 0)
935 return rc;
936 }
937
82237416 938 /* PAGE_SIZE buffer shall be enough and dma aligned */
e080842c 939 msg = kmalloc(PAGE_SIZE, GFP_KERNEL | GFP_DMA);
2e5c1ec8
MK
940 if (!msg)
941 return -ENOMEM;
942
82237416 943 if (coredev->mode != DEVICE_MODE_NONE) {
2522dc13 944 sms_debug("sending reload command.");
dfef84fc
MCC
945 SMS_INIT_MSG(&msg->x_msg_header, MSG_SW_RELOAD_START_REQ,
946 sizeof(struct sms_msg_hdr));
82237416 947 rc = smscore_sendrequest_and_wait(coredev, msg,
dfef84fc 948 msg->x_msg_header.msg_length,
82237416 949 &coredev->reload_start_done);
018b0c6f
MCC
950 if (rc < 0) {
951 sms_err("device reload failed, rc %d", rc);
952 goto exit_fw_download;
953 }
f0333e3d 954 mem_address = *(u32 *) &payload[20];
2e5c1ec8
MK
955 }
956
dfef84fc 957 for (i = 0, ptr = (u32 *)firmware->payload; i < firmware->length/4 ;
018b0c6f
MCC
958 i++, ptr++)
959 calc_checksum += *ptr;
960
fa830e8a 961 while (size && rc >= 0) {
dfef84fc
MCC
962 struct sms_data_download *DataMsg =
963 (struct sms_data_download *) msg;
2e5c1ec8
MK
964 int payload_size = min((int) size, SMS_MAX_PAYLOAD_SIZE);
965
dfef84fc
MCC
966 SMS_INIT_MSG(&msg->x_msg_header, MSG_SMS_DATA_DOWNLOAD_REQ,
967 (u16)(sizeof(struct sms_msg_hdr) +
f0333e3d 968 sizeof(u32) + payload_size));
2e5c1ec8 969
dfef84fc
MCC
970 DataMsg->mem_addr = mem_address;
971 memcpy(DataMsg->payload, payload, payload_size);
2e5c1ec8 972
018b0c6f 973 rc = smscore_sendrequest_and_wait(coredev, DataMsg,
dfef84fc 974 DataMsg->x_msg_header.msg_length,
59bf6b8e 975 &coredev->data_download_done);
2e5c1ec8
MK
976
977 payload += payload_size;
978 size -= payload_size;
979 mem_address += payload_size;
980 }
981
018b0c6f
MCC
982 if (rc < 0)
983 goto exit_fw_download;
984
985 sms_err("sending MSG_SMS_DATA_VALIDITY_REQ expecting 0x%x",
986 calc_checksum);
dfef84fc
MCC
987 SMS_INIT_MSG(&msg->x_msg_header, MSG_SMS_DATA_VALIDITY_REQ,
988 sizeof(msg->x_msg_header) +
018b0c6f 989 sizeof(u32) * 3);
dfef84fc 990 msg->msgData[0] = firmware->start_address;
018b0c6f 991 /* Entry point */
dfef84fc 992 msg->msgData[1] = firmware->length;
018b0c6f 993 msg->msgData[2] = 0; /* Regular checksum*/
018b0c6f 994 rc = smscore_sendrequest_and_wait(coredev, msg,
dfef84fc 995 msg->x_msg_header.msg_length,
018b0c6f
MCC
996 &coredev->data_validity_done);
997 if (rc < 0)
998 goto exit_fw_download;
999
1000 if (coredev->mode == DEVICE_MODE_NONE) {
dfef84fc
MCC
1001 struct sms_msg_data *TriggerMsg =
1002 (struct sms_msg_data *) msg;
018b0c6f
MCC
1003
1004 sms_debug("sending MSG_SMS_SWDOWNLOAD_TRIGGER_REQ");
dfef84fc 1005 SMS_INIT_MSG(&msg->x_msg_header,
018b0c6f 1006 MSG_SMS_SWDOWNLOAD_TRIGGER_REQ,
dfef84fc 1007 sizeof(struct sms_msg_hdr) +
018b0c6f
MCC
1008 sizeof(u32) * 5);
1009
dfef84fc 1010 TriggerMsg->msgData[0] = firmware->start_address;
018b0c6f
MCC
1011 /* Entry point */
1012 TriggerMsg->msgData[1] = 6; /* Priority */
1013 TriggerMsg->msgData[2] = 0x200; /* Stack size */
1014 TriggerMsg->msgData[3] = 0; /* Parameter */
1015 TriggerMsg->msgData[4] = 4; /* Task ID */
1016
018b0c6f 1017 rc = smscore_sendrequest_and_wait(coredev, TriggerMsg,
dfef84fc 1018 TriggerMsg->x_msg_header.msg_length,
59bf6b8e 1019 &coredev->trigger_done);
018b0c6f 1020 } else {
dfef84fc
MCC
1021 SMS_INIT_MSG(&msg->x_msg_header, MSG_SW_RELOAD_EXEC_REQ,
1022 sizeof(struct sms_msg_hdr));
018b0c6f 1023 rc = coredev->sendrequest_handler(coredev->context, msg,
dfef84fc 1024 msg->x_msg_header.msg_length);
2e5c1ec8
MK
1025 }
1026
018b0c6f
MCC
1027 if (rc < 0)
1028 goto exit_fw_download;
1029
1030 /*
1031 * backward compatibility - wait to device_ready_done for
1032 * not more than 400 ms
1033 */
1034 msleep(400);
1035
1036exit_fw_download:
2e5c1ec8
MK
1037 kfree(msg);
1038
1e19c21e
MCC
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);
1043 }
1044
1045 sms_debug("rc=%d", rc);
1046 return rc;
2e5c1ec8
MK
1047}
1048
2a764315
MCC
1049static char *smscore_fw_lkup[][DEVICE_MODE_MAX] = {
1050 [SMS_NOVA_A0] = {
11ad03a5
MCC
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,
2a764315
MCC
1057 },
1058 [SMS_NOVA_B0] = {
11ad03a5
MCC
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,
2a764315
MCC
1067 },
1068 [SMS_VEGA] = {
11ad03a5 1069 [DEVICE_MODE_CMMB] = SMS_FW_CMMB_VEGA_12MHZ,
2a764315
MCC
1070 },
1071 [SMS_VENICE] = {
11ad03a5 1072 [DEVICE_MODE_CMMB] = SMS_FW_CMMB_VENICE_12MHZ,
2a764315
MCC
1073 },
1074 [SMS_MING] = {
11ad03a5 1075 [DEVICE_MODE_CMMB] = SMS_FW_CMMB_MING_APP,
2a764315
MCC
1076 },
1077 [SMS_PELE] = {
11ad03a5
MCC
1078 [DEVICE_MODE_ISDBT] = SMS_FW_ISDBT_PELE,
1079 [DEVICE_MODE_ISDBT_BDA] = SMS_FW_ISDBT_PELE,
2a764315
MCC
1080 },
1081 [SMS_RIO] = {
11ad03a5
MCC
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,
2a764315
MCC
1089 },
1090 [SMS_DENVER_1530] = {
11ad03a5 1091 [DEVICE_MODE_ATSC] = SMS_FW_ATSC_DENVER,
2a764315
MCC
1092 },
1093 [SMS_DENVER_2160] = {
11ad03a5 1094 [DEVICE_MODE_DAB_TDMB] = SMS_FW_TDMB_DENVER,
2a764315
MCC
1095 },
1096};
018b0c6f 1097
2a764315
MCC
1098/**
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
1106 *
1107 * @return 0 on success, <0 on error.
1108 */
018b0c6f 1109static char *smscore_get_fw_filename(struct smscore_device_t *coredev,
2a764315
MCC
1110 int mode)
1111{
1112 char **fw;
1113 int board_id = smscore_get_board_id(coredev);
1114 enum sms_device_type_st type;
1115
1116 type = smscore_registry_gettype(coredev->devpath);
1117
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;
1123
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];
1131 }
1132
1133 return fw[mode];
1134}
018b0c6f 1135
2e5c1ec8
MK
1136/**
1137 * loads specified firmware into a buffer and calls device loadfirmware_handler
1138 *
59bf6b8e
MK
1139 * @param coredev pointer to a coredev object returned by
1140 * smscore_register_device
2e5c1ec8
MK
1141 * @param filename null-terminated string specifies firmware file name
1142 * @param loadfirmware_handler device handler that loads firmware
1143 *
1144 * @return 0 on success, <0 on error.
1145 */
0c071f37 1146static int smscore_load_firmware_from_file(struct smscore_device_t *coredev,
e584f9d6 1147 int mode,
0c071f37 1148 loadfirmware_t loadfirmware_handler)
2e5c1ec8
MK
1149{
1150 int rc = -ENOENT;
018b0c6f
MCC
1151 u8 *fw_buf;
1152 u32 fw_buf_size;
2e5c1ec8 1153 const struct firmware *fw;
2e5c1ec8 1154
e584f9d6 1155 char *fw_filename = smscore_get_fw_filename(coredev, mode);
5ac14b60
MCC
1156 if (!fw_filename) {
1157 sms_info("mode %d not supported on this device", mode);
018b0c6f 1158 return -ENOENT;
5ac14b60
MCC
1159 }
1160 sms_debug("Firmware name: %s", fw_filename);
018b0c6f
MCC
1161
1162 if (loadfirmware_handler == NULL && !(coredev->device_flags
1163 & SMS_DEVICE_FAMILY2))
2e5c1ec8
MK
1164 return -EINVAL;
1165
018b0c6f 1166 rc = request_firmware(&fw, fw_filename, coredev->device);
82237416 1167 if (rc < 0) {
018b0c6f 1168 sms_info("failed to open \"%s\"", fw_filename);
2e5c1ec8
MK
1169 return rc;
1170 }
018b0c6f
MCC
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) {
a0c0abcb 1175 sms_info("failed to allocate firmware buffer");
018b0c6f 1176 return -ENOMEM;
2e5c1ec8 1177 }
018b0c6f
MCC
1178 memcpy(fw_buf, fw->data, fw->size);
1179 fw_buf_size = fw->size;
1180
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);
2e5c1ec8 1185
018b0c6f 1186 kfree(fw_buf);
2e5c1ec8
MK
1187 release_firmware(fw);
1188
1189 return rc;
1190}
1191
1192/**
59bf6b8e
MK
1193 * notifies all clients registered with the device, notifies hotplugs,
1194 * frees all buffers and coredev object
2e5c1ec8 1195 *
59bf6b8e
MK
1196 * @param coredev pointer to a coredev object returned by
1197 * smscore_register_device
2e5c1ec8
MK
1198 *
1199 * @return 0 on success, <0 on error.
1200 */
18245e18 1201void smscore_unregister_device(struct smscore_device_t *coredev)
2e5c1ec8 1202{
18245e18 1203 struct smscore_buffer_t *cb;
2e5c1ec8 1204 int num_buffers = 0;
f17407a8 1205 int retry = 0;
2e5c1ec8
MK
1206
1207 kmutex_lock(&g_smscore_deviceslock);
1208
a804800a
US
1209 /* Release input device (IR) resources */
1210 sms_ir_exit(coredev);
1211
2e5c1ec8
MK
1212 smscore_notify_clients(coredev);
1213 smscore_notify_callbacks(coredev, NULL, 0);
1214
82237416
MK
1215 /* at this point all buffers should be back
1216 * onresponse must no longer be called */
2e5c1ec8 1217
82237416 1218 while (1) {
a9349315
US
1219 while (!list_empty(&coredev->buffers)) {
1220 cb = (struct smscore_buffer_t *) coredev->buffers.next;
1221 list_del(&cb->entry);
2e5c1ec8 1222 kfree(cb);
fa830e8a 1223 num_buffers++;
2e5c1ec8 1224 }
2e5c1ec8
MK
1225 if (num_buffers == coredev->num_buffers)
1226 break;
82237416 1227 if (++retry > 10) {
a0c0abcb
MK
1228 sms_info("exiting although "
1229 "not all buffers released.");
f17407a8
MK
1230 break;
1231 }
2e5c1ec8 1232
a0c0abcb 1233 sms_info("waiting for %d buffer(s)",
068d6c0f 1234 coredev->num_buffers - num_buffers);
018b0c6f 1235 kmutex_unlock(&g_smscore_deviceslock);
2e5c1ec8 1236 msleep(100);
018b0c6f 1237 kmutex_lock(&g_smscore_deviceslock);
2e5c1ec8
MK
1238 }
1239
a0c0abcb 1240 sms_info("freed %d buffers", num_buffers);
2e5c1ec8
MK
1241
1242 if (coredev->common_buffer)
82237416 1243 dma_free_coherent(NULL, coredev->common_buffer_size,
a9349315
US
1244 coredev->common_buffer, coredev->common_buffer_phys);
1245
2da8eab9 1246 kfree(coredev->fw_buf);
2e5c1ec8
MK
1247
1248 list_del(&coredev->entry);
1249 kfree(coredev);
1250
1251 kmutex_unlock(&g_smscore_deviceslock);
1252
a0c0abcb 1253 sms_info("device %p destroyed", coredev);
2e5c1ec8 1254}
a0beec8f 1255EXPORT_SYMBOL_GPL(smscore_unregister_device);
2e5c1ec8 1256
0c071f37 1257static int smscore_detect_mode(struct smscore_device_t *coredev)
2e5c1ec8 1258{
dfef84fc 1259 void *buffer = kmalloc(sizeof(struct sms_msg_hdr) + SMS_DMA_ALIGNMENT,
82237416 1260 GFP_KERNEL | GFP_DMA);
dfef84fc
MCC
1261 struct sms_msg_hdr *msg =
1262 (struct sms_msg_hdr *) SMS_ALIGN_ADDRESS(buffer);
2e5c1ec8
MK
1263 int rc;
1264
1265 if (!buffer)
1266 return -ENOMEM;
1267
18245e18 1268 SMS_INIT_MSG(msg, MSG_SMS_GET_VERSION_EX_REQ,
dfef84fc 1269 sizeof(struct sms_msg_hdr));
2e5c1ec8 1270
dfef84fc 1271 rc = smscore_sendrequest_and_wait(coredev, msg, msg->msg_length,
82237416
MK
1272 &coredev->version_ex_done);
1273 if (rc == -ETIME) {
a0c0abcb 1274 sms_err("MSG_SMS_GET_VERSION_EX_REQ failed first try");
2e5c1ec8 1275
82237416
MK
1276 if (wait_for_completion_timeout(&coredev->resume_done,
1277 msecs_to_jiffies(5000))) {
59bf6b8e 1278 rc = smscore_sendrequest_and_wait(
dfef84fc 1279 coredev, msg, msg->msg_length,
59bf6b8e 1280 &coredev->version_ex_done);
2e5c1ec8 1281 if (rc < 0)
a0c0abcb
MK
1282 sms_err("MSG_SMS_GET_VERSION_EX_REQ failed "
1283 "second try, rc %d", rc);
82237416 1284 } else
2e5c1ec8
MK
1285 rc = -ETIME;
1286 }
1287
1288 kfree(buffer);
1289
1290 return rc;
1291}
1292
fe802fd9
MCC
1293/**
1294 * send init device request and wait for response
1295 *
1296 * @param coredev pointer to a coredev object returned by
1297 * smscore_register_device
1298 * @param mode requested mode of operation
1299 *
1300 * @return 0 on success, <0 on error.
1301 */
1302int smscore_init_device(struct smscore_device_t *coredev, int mode)
1303{
1304 void *buffer;
dfef84fc 1305 struct sms_msg_data *msg;
fe802fd9
MCC
1306 int rc = 0;
1307
dfef84fc 1308 buffer = kmalloc(sizeof(struct sms_msg_data) +
fe802fd9
MCC
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;
1313 }
1314
dfef84fc
MCC
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));
fe802fd9
MCC
1318 msg->msgData[0] = mode;
1319
fe802fd9 1320 rc = smscore_sendrequest_and_wait(coredev, msg,
dfef84fc 1321 msg->x_msg_header. msg_length,
fe802fd9
MCC
1322 &coredev->init_device_done);
1323
1324 kfree(buffer);
1325 return rc;
1326}
1327
2e5c1ec8
MK
1328/**
1329 * calls device handler to change mode of operation
1330 * NOTE: stellar/usb may disconnect when changing mode
1331 *
59bf6b8e
MK
1332 * @param coredev pointer to a coredev object returned by
1333 * smscore_register_device
2e5c1ec8
MK
1334 * @param mode requested mode of operation
1335 *
1336 * @return 0 on success, <0 on error.
1337 */
18245e18 1338int smscore_set_device_mode(struct smscore_device_t *coredev, int mode)
2e5c1ec8 1339{
2e5c1ec8
MK
1340 int rc = 0;
1341
2522dc13 1342 sms_debug("set device mode to %d", mode);
82237416 1343 if (coredev->device_flags & SMS_DEVICE_FAMILY2) {
9711a8a6 1344 if (mode <= DEVICE_MODE_NONE || mode >= DEVICE_MODE_MAX) {
eb250942 1345 sms_err("invalid mode specified %d", mode);
2e5c1ec8
MK
1346 return -EINVAL;
1347 }
1348
f17407a8
MK
1349 smscore_registry_setmode(coredev->devpath, mode);
1350
82237416 1351 if (!(coredev->device_flags & SMS_DEVICE_NOT_READY)) {
2e5c1ec8 1352 rc = smscore_detect_mode(coredev);
82237416 1353 if (rc < 0) {
eb250942 1354 sms_err("mode detect failed %d", rc);
2e5c1ec8 1355 return rc;
82237416 1356 }
f17407a8 1357 }
2e5c1ec8 1358
82237416 1359 if (coredev->mode == mode) {
a0c0abcb 1360 sms_info("device mode %d already set", mode);
2e5c1ec8
MK
1361 return 0;
1362 }
1363
82237416 1364 if (!(coredev->modes_supported & (1 << mode))) {
02aea4fb 1365 rc = smscore_load_firmware_from_file(coredev,
e584f9d6 1366 mode, NULL);
018b0c6f
MCC
1367 if (rc >= 0)
1368 sms_info("firmware download success");
82237416 1369 } else {
018b0c6f
MCC
1370 sms_info("mode %d is already supported by running firmware",
1371 mode);
82237416 1372 }
fe802fd9
MCC
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);
1377 }
82237416 1378 } else {
9711a8a6 1379 if (mode <= DEVICE_MODE_NONE || mode >= DEVICE_MODE_MAX) {
eb250942 1380 sms_err("invalid mode specified %d", mode);
f17407a8
MK
1381 return -EINVAL;
1382 }
1383
1384 smscore_registry_setmode(coredev->devpath, mode);
1385
2e5c1ec8 1386 if (coredev->detectmode_handler)
82237416
MK
1387 coredev->detectmode_handler(coredev->context,
1388 &coredev->mode);
2e5c1ec8
MK
1389
1390 if (coredev->mode != mode && coredev->setmode_handler)
1391 rc = coredev->setmode_handler(coredev->context, mode);
1392 }
1393
82237416 1394 if (rc >= 0) {
018b0c6f 1395 char *buffer;
2e5c1ec8
MK
1396 coredev->mode = mode;
1397 coredev->device_flags &= ~SMS_DEVICE_NOT_READY;
018b0c6f 1398
dfef84fc 1399 buffer = kmalloc(sizeof(struct sms_msg_data) +
018b0c6f
MCC
1400 SMS_DMA_ALIGNMENT, GFP_KERNEL | GFP_DMA);
1401 if (buffer) {
dfef84fc 1402 struct sms_msg_data *msg = (struct sms_msg_data *) SMS_ALIGN_ADDRESS(buffer);
018b0c6f 1403
dfef84fc
MCC
1404 SMS_INIT_MSG(&msg->x_msg_header, MSG_SMS_INIT_DEVICE_REQ,
1405 sizeof(struct sms_msg_data));
018b0c6f
MCC
1406 msg->msgData[0] = mode;
1407
1408 rc = smscore_sendrequest_and_wait(
dfef84fc 1409 coredev, msg, msg->x_msg_header.msg_length,
018b0c6f
MCC
1410 &coredev->init_device_done);
1411
1412 kfree(buffer);
1413 }
2e5c1ec8
MK
1414 }
1415
5d2387e3 1416 if (rc < 0)
eb250942 1417 sms_err("return error code %d.", rc);
e5d218ee
MCC
1418 else
1419 sms_debug("Success setting device mode.");
1420
2e5c1ec8
MK
1421 return rc;
1422}
1423
1424/**
1425 * calls device handler to get current mode of operation
1426 *
59bf6b8e
MK
1427 * @param coredev pointer to a coredev object returned by
1428 * smscore_register_device
2e5c1ec8
MK
1429 *
1430 * @return current mode
1431 */
18245e18 1432int smscore_get_device_mode(struct smscore_device_t *coredev)
2e5c1ec8
MK
1433{
1434 return coredev->mode;
1435}
a0beec8f 1436EXPORT_SYMBOL_GPL(smscore_get_device_mode);
2e5c1ec8 1437
f17407a8
MK
1438/**
1439 * find client by response id & type within the clients list.
1440 * return client handle or NULL.
1441 *
59bf6b8e
MK
1442 * @param coredev pointer to a coredev object returned by
1443 * smscore_register_device
f17407a8 1444 * @param data_type client data type (SMS_DONT_CARE for all types)
82237416 1445 * @param id client id (SMS_DONT_CARE for all id)
f17407a8
MK
1446 *
1447 */
0c071f37
MK
1448static struct
1449smscore_client_t *smscore_find_client(struct smscore_device_t *coredev,
59bf6b8e 1450 int data_type, int id)
2e5c1ec8 1451{
0208c15e
JL
1452 struct list_head *first;
1453 struct smscore_client_t *client;
2e5c1ec8 1454 unsigned long flags;
0208c15e
JL
1455 struct list_head *firstid;
1456 struct smscore_idlist_t *client_id;
2e5c1ec8
MK
1457
1458 spin_lock_irqsave(&coredev->clientslock, flags);
2e5c1ec8 1459 first = &coredev->clients;
0208c15e
JL
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;
2e5c1ec8
MK
1467 }
1468 }
0208c15e
JL
1469 client = NULL;
1470found:
2e5c1ec8 1471 spin_unlock_irqrestore(&coredev->clientslock, flags);
2e5c1ec8
MK
1472 return client;
1473}
1474
1475/**
1476 * find client by response id/type, call clients onresponse handler
1477 * return buffer to pool on error
1478 *
59bf6b8e
MK
1479 * @param coredev pointer to a coredev object returned by
1480 * smscore_register_device
2e5c1ec8
MK
1481 * @param cb pointer to response buffer descriptor
1482 *
1483 */
18245e18 1484void smscore_onresponse(struct smscore_device_t *coredev,
793786d1 1485 struct smscore_buffer_t *cb) {
dfef84fc 1486 struct sms_msg_hdr *phdr = (struct sms_msg_hdr *) ((u8 *) cb->p
793786d1
US
1487 + cb->offset);
1488 struct smscore_client_t *client;
2e5c1ec8 1489 int rc = -EBUSY;
fbd05c82
MK
1490 static unsigned long last_sample_time; /* = 0; */
1491 static int data_total; /* = 0; */
2e5c1ec8
MK
1492 unsigned long time_now = jiffies_to_msecs(jiffies);
1493
1494 if (!last_sample_time)
1495 last_sample_time = time_now;
1496
fa830e8a 1497 if (time_now - last_sample_time > 10000) {
98c3f94e 1498 sms_debug("data rate %d bytes/secs",
068d6c0f
MK
1499 (int)((data_total * 1000) /
1500 (time_now - last_sample_time)));
2e5c1ec8
MK
1501
1502 last_sample_time = time_now;
1503 data_total = 0;
1504 }
1505
1506 data_total += cb->size;
793786d1 1507 /* Do we need to re-route? */
dfef84fc
MCC
1508 if ((phdr->msg_type == MSG_SMS_HO_PER_SLICES_IND) ||
1509 (phdr->msg_type == MSG_SMS_TRANSMISSION_IND)) {
793786d1 1510 if (coredev->mode == DEVICE_MODE_DVBT_BDA)
dfef84fc 1511 phdr->msg_dst_id = DVBT_BDA_CONTROL_MSG_ID;
793786d1
US
1512 }
1513
1514
dfef84fc 1515 client = smscore_find_client(coredev, phdr->msg_type, phdr->msg_dst_id);
793786d1 1516
82237416
MK
1517 /* If no client registered for type & id,
1518 * check for control client where type is not registered */
2e5c1ec8
MK
1519 if (client)
1520 rc = client->onresponse_handler(client->context, cb);
1521
82237416 1522 if (rc < 0) {
dfef84fc 1523 switch (phdr->msg_type) {
faab6820
MCC
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;
82237416 1538 case MSG_SMS_GET_VERSION_EX_RES:
2e5c1ec8 1539 {
dfef84fc
MCC
1540 struct sms_version_res *ver =
1541 (struct sms_version_res *) phdr;
4c3bdb5e 1542 sms_debug("Firmware id %d prots 0x%x ver %d.%d",
dfef84fc
MCC
1543 ver->firmware_id, ver->supported_protocols,
1544 ver->rom_ver_major, ver->rom_ver_minor);
2e5c1ec8 1545
dfef84fc
MCC
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;
2e5c1ec8 1551
82237416
MK
1552 complete(&coredev->version_ex_done);
1553 break;
1554 }
1555 case MSG_SMS_INIT_DEVICE_RES:
82237416
MK
1556 complete(&coredev->init_device_done);
1557 break;
1558 case MSG_SW_RELOAD_START_RES:
82237416
MK
1559 complete(&coredev->reload_start_done);
1560 break;
018b0c6f
MCC
1561 case MSG_SMS_DATA_VALIDITY_RES:
1562 {
dfef84fc 1563 struct sms_msg_data *validity = (struct sms_msg_data *) phdr;
018b0c6f
MCC
1564
1565 sms_err("MSG_SMS_DATA_VALIDITY_RES, checksum = 0x%x",
1566 validity->msgData[0]);
1567 complete(&coredev->data_validity_done);
1568 break;
1569 }
82237416
MK
1570 case MSG_SMS_DATA_DOWNLOAD_RES:
1571 complete(&coredev->data_download_done);
1572 break;
1573 case MSG_SW_RELOAD_EXEC_RES:
82237416
MK
1574 break;
1575 case MSG_SMS_SWDOWNLOAD_TRIGGER_RES:
82237416
MK
1576 complete(&coredev->trigger_done);
1577 break;
1578 case MSG_SMS_SLEEP_RESUME_COMP_IND:
1579 complete(&coredev->resume_done);
1580 break;
34601caa 1581 case MSG_SMS_GPIO_CONFIG_EX_RES:
34601caa
US
1582 complete(&coredev->gpio_configuration_done);
1583 break;
1584 case MSG_SMS_GPIO_SET_LEVEL_RES:
34601caa
US
1585 complete(&coredev->gpio_set_level_done);
1586 break;
1587 case MSG_SMS_GPIO_GET_LEVEL_RES:
1588 {
1589 u32 *msgdata = (u32 *) phdr;
1590 coredev->gpio_get_res = msgdata[1];
4c3bdb5e 1591 sms_debug("gpio level %d",
34601caa
US
1592 coredev->gpio_get_res);
1593 complete(&coredev->gpio_get_level_done);
1594 break;
1595 }
a804800a
US
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
dfef84fc
MCC
1603 + sizeof(struct sms_msg_hdr)),
1604 (int)phdr->msg_length
1605 - sizeof(struct sms_msg_hdr));
a804800a
US
1606 break;
1607
d8a18e88
MCC
1608 case MSG_SMS_DVBT_BDA_DATA:
1609 /*
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
1614 */
1615 break;
1616
82237416 1617 default:
98c3f94e 1618 sms_debug("message %s(%d) not handled.",
dfef84fc
MCC
1619 smscore_translate_msg(phdr->msg_type),
1620 phdr->msg_type);
82237416 1621 break;
2e5c1ec8 1622 }
2e5c1ec8
MK
1623 smscore_putbuffer(coredev, cb);
1624 }
1625}
a0beec8f 1626EXPORT_SYMBOL_GPL(smscore_onresponse);
2e5c1ec8
MK
1627
1628/**
1629 * return pointer to next free buffer descriptor from core pool
1630 *
59bf6b8e
MK
1631 * @param coredev pointer to a coredev object returned by
1632 * smscore_register_device
2e5c1ec8
MK
1633 *
1634 * @return pointer to descriptor on success, NULL on error.
1635 */
3cdadc50 1636
c246ffc2 1637static struct smscore_buffer_t *get_entry(struct smscore_device_t *coredev)
2e5c1ec8 1638{
18245e18 1639 struct smscore_buffer_t *cb = NULL;
2e5c1ec8
MK
1640 unsigned long flags;
1641
1642 spin_lock_irqsave(&coredev->bufferslock, flags);
3cdadc50
RZ
1643 if (!list_empty(&coredev->buffers)) {
1644 cb = (struct smscore_buffer_t *) coredev->buffers.next;
1645 list_del(&cb->entry);
d0a38ce2 1646 }
3cdadc50
RZ
1647 spin_unlock_irqrestore(&coredev->bufferslock, flags);
1648 return cb;
1649}
a9349315 1650
3cdadc50
RZ
1651struct smscore_buffer_t *smscore_getbuffer(struct smscore_device_t *coredev)
1652{
1653 struct smscore_buffer_t *cb = NULL;
2e5c1ec8 1654
3cdadc50 1655 wait_event(coredev->buffer_mng_waitq, (cb = get_entry(coredev)));
2e5c1ec8
MK
1656
1657 return cb;
1658}
a0beec8f 1659EXPORT_SYMBOL_GPL(smscore_getbuffer);
2e5c1ec8
MK
1660
1661/**
1662 * return buffer descriptor to a pool
1663 *
59bf6b8e
MK
1664 * @param coredev pointer to a coredev object returned by
1665 * smscore_register_device
2e5c1ec8
MK
1666 * @param cb pointer buffer descriptor
1667 *
1668 */
18245e18 1669void smscore_putbuffer(struct smscore_device_t *coredev,
a9349315
US
1670 struct smscore_buffer_t *cb) {
1671 wake_up_interruptible(&coredev->buffer_mng_waitq);
2e5c1ec8
MK
1672 list_add_locked(&cb->entry, &coredev->buffers, &coredev->bufferslock);
1673}
a0beec8f 1674EXPORT_SYMBOL_GPL(smscore_putbuffer);
2e5c1ec8 1675
0c071f37
MK
1676static int smscore_validate_client(struct smscore_device_t *coredev,
1677 struct smscore_client_t *client,
1678 int data_type, int id)
2e5c1ec8 1679{
18245e18
MK
1680 struct smscore_idlist_t *listentry;
1681 struct smscore_client_t *registered_client;
2e5c1ec8 1682
82237416 1683 if (!client) {
2522dc13 1684 sms_err("bad parameter.");
d316b5fb 1685 return -EINVAL;
f17407a8
MK
1686 }
1687 registered_client = smscore_find_client(coredev, data_type, id);
fa830e8a 1688 if (registered_client == client)
2e5c1ec8 1689 return 0;
fa830e8a 1690
82237416 1691 if (registered_client) {
2522dc13 1692 sms_err("The msg ID already registered to another client.");
f17407a8
MK
1693 return -EEXIST;
1694 }
18245e18 1695 listentry = kzalloc(sizeof(struct smscore_idlist_t), GFP_KERNEL);
82237416 1696 if (!listentry) {
2522dc13 1697 sms_err("Can't allocate memory for client id.");
2e5c1ec8 1698 return -ENOMEM;
f17407a8
MK
1699 }
1700 listentry->id = id;
1701 listentry->data_type = data_type;
82237416
MK
1702 list_add_locked(&listentry->entry, &client->idlist,
1703 &coredev->clientslock);
2e5c1ec8
MK
1704 return 0;
1705}
1706
1707/**
1708 * creates smsclient object, check that id is taken by another client
1709 *
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
ca783736
MK
1713 * @param onresponse_handler client handler that is called to
1714 * process incoming messages
2e5c1ec8
MK
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
1718 *
1719 * @return 0 on success, <0 on error.
1720 */
18245e18
MK
1721int smscore_register_client(struct smscore_device_t *coredev,
1722 struct smsclient_params_t *params,
1723 struct smscore_client_t **client)
2e5c1ec8 1724{
18245e18 1725 struct smscore_client_t *newclient;
82237416
MK
1726 /* check that no other channel with same parameters exists */
1727 if (smscore_find_client(coredev, params->data_type,
1728 params->initial_id)) {
2522dc13 1729 sms_err("Client already exist.");
2e5c1ec8 1730 return -EEXIST;
f17407a8 1731 }
2e5c1ec8 1732
18245e18 1733 newclient = kzalloc(sizeof(struct smscore_client_t), GFP_KERNEL);
82237416 1734 if (!newclient) {
2522dc13 1735 sms_err("Failed to allocate memory for client.");
f17407a8 1736 return -ENOMEM;
2e5c1ec8
MK
1737 }
1738
82237416 1739 INIT_LIST_HEAD(&newclient->idlist);
2e5c1ec8 1740 newclient->coredev = coredev;
2e5c1ec8
MK
1741 newclient->onresponse_handler = params->onresponse_handler;
1742 newclient->onremove_handler = params->onremove_handler;
1743 newclient->context = params->context;
82237416
MK
1744 list_add_locked(&newclient->entry, &coredev->clients,
1745 &coredev->clientslock);
1746 smscore_validate_client(coredev, newclient, params->data_type,
1747 params->initial_id);
2e5c1ec8 1748 *client = newclient;
2522dc13
MK
1749 sms_debug("%p %d %d", params->context, params->data_type,
1750 params->initial_id);
2e5c1ec8
MK
1751
1752 return 0;
1753}
a0beec8f 1754EXPORT_SYMBOL_GPL(smscore_register_client);
2e5c1ec8
MK
1755
1756/**
1757 * frees smsclient object and all subclients associated with it
1758 *
59bf6b8e
MK
1759 * @param client pointer to smsclient object returned by
1760 * smscore_register_client
2e5c1ec8
MK
1761 *
1762 */
18245e18 1763void smscore_unregister_client(struct smscore_client_t *client)
2e5c1ec8 1764{
18245e18 1765 struct smscore_device_t *coredev = client->coredev;
2e5c1ec8
MK
1766 unsigned long flags;
1767
1768 spin_lock_irqsave(&coredev->clientslock, flags);
1769
2e5c1ec8 1770
82237416 1771 while (!list_empty(&client->idlist)) {
18245e18
MK
1772 struct smscore_idlist_t *identry =
1773 (struct smscore_idlist_t *) client->idlist.next;
82237416
MK
1774 list_del(&identry->entry);
1775 kfree(identry);
2e5c1ec8
MK
1776 }
1777
a0c0abcb 1778 sms_info("%p", client->context);
2e5c1ec8
MK
1779
1780 list_del(&client->entry);
1781 kfree(client);
1782
1783 spin_unlock_irqrestore(&coredev->clientslock, flags);
1784}
a0beec8f 1785EXPORT_SYMBOL_GPL(smscore_unregister_client);
2e5c1ec8
MK
1786
1787/**
1788 * verifies that source id is not taken by another client,
1789 * calls device handler to send requests to the device
1790 *
59bf6b8e
MK
1791 * @param client pointer to smsclient object returned by
1792 * smscore_register_client
2e5c1ec8
MK
1793 * @param buffer pointer to a request buffer
1794 * @param size size (in bytes) of request buffer
1795 *
1796 * @return 0 on success, <0 on error.
1797 */
18245e18
MK
1798int smsclient_sendrequest(struct smscore_client_t *client,
1799 void *buffer, size_t size)
2e5c1ec8 1800{
18245e18 1801 struct smscore_device_t *coredev;
dfef84fc 1802 struct sms_msg_hdr *phdr = (struct sms_msg_hdr *) buffer;
f17407a8
MK
1803 int rc;
1804
82237416 1805 if (client == NULL) {
a0c0abcb 1806 sms_err("Got NULL client");
f17407a8
MK
1807 return -EINVAL;
1808 }
1809
1810 coredev = client->coredev;
2e5c1ec8 1811
82237416
MK
1812 /* check that no other channel with same id exists */
1813 if (coredev == NULL) {
a0c0abcb 1814 sms_err("Got NULL coredev");
f17407a8
MK
1815 return -EINVAL;
1816 }
1817
82237416 1818 rc = smscore_validate_client(client->coredev, client, 0,
dfef84fc 1819 phdr->msg_src_id);
2e5c1ec8
MK
1820 if (rc < 0)
1821 return rc;
1822
1823 return coredev->sendrequest_handler(coredev->context, buffer, size);
1824}
a0beec8f 1825EXPORT_SYMBOL_GPL(smsclient_sendrequest);
2e5c1ec8 1826
2e5c1ec8 1827
65155b37 1828/* old GPIO managements implementation */
76052bc8 1829int smscore_configure_gpio(struct smscore_device_t *coredev, u32 pin,
7c4ca79f 1830 struct smscore_config_gpio *pinconfig)
76052bc8
MK
1831{
1832 struct {
dfef84fc 1833 struct sms_msg_hdr hdr;
76052bc8
MK
1834 u32 data[6];
1835 } msg;
1836
1837 if (coredev->device_flags & SMS_DEVICE_FAMILY2) {
dfef84fc
MCC
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);
76052bc8
MK
1843
1844 msg.data[0] = pin;
1845 msg.data[1] = pinconfig->pullupdown;
1846
1847 /* Convert slew rate for Nova: Fast(0) = 3 / Slow(1) = 0; */
1848 msg.data[2] = pinconfig->outputslewrate == 0 ? 3 : 0;
1849
1850 switch (pinconfig->outputdriving) {
f82757d9 1851 case SMS_GPIO_OUTPUTDRIVING_S_16mA:
76052bc8
MK
1852 msg.data[3] = 7; /* Nova - 16mA */
1853 break;
f82757d9 1854 case SMS_GPIO_OUTPUTDRIVING_S_12mA:
76052bc8
MK
1855 msg.data[3] = 5; /* Nova - 11mA */
1856 break;
f82757d9 1857 case SMS_GPIO_OUTPUTDRIVING_S_8mA:
76052bc8
MK
1858 msg.data[3] = 3; /* Nova - 7mA */
1859 break;
f82757d9 1860 case SMS_GPIO_OUTPUTDRIVING_S_4mA:
76052bc8
MK
1861 default:
1862 msg.data[3] = 2; /* Nova - 4mA */
1863 break;
1864 }
1865
1866 msg.data[4] = pinconfig->direction;
1867 msg.data[5] = 0;
1868 } else /* TODO: SMS_DEVICE_FAMILY1 */
1869 return -EINVAL;
1870
1871 return coredev->sendrequest_handler(coredev->context,
1872 &msg, sizeof(msg));
1873}
1874
1875int smscore_set_gpio(struct smscore_device_t *coredev, u32 pin, int level)
1876{
1877 struct {
dfef84fc 1878 struct sms_msg_hdr hdr;
76052bc8
MK
1879 u32 data[3];
1880 } msg;
1881
1882 if (pin > MAX_GPIO_PIN_NUMBER)
1883 return -EINVAL;
1884
dfef84fc
MCC
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);
76052bc8
MK
1890
1891 msg.data[0] = pin;
1892 msg.data[1] = level ? 1 : 0;
1893 msg.data[2] = 0;
1894
1895 return coredev->sendrequest_handler(coredev->context,
1896 &msg, sizeof(msg));
1897}
1898
3dbda77e 1899/* new GPIO management implementation */
dfef84fc 1900static int GetGpioPinParams(u32 pin_num, u32 *pTranslatedpin_num,
7c4ca79f
US
1901 u32 *pGroupNum, u32 *pGroupCfg) {
1902
1903 *pGroupCfg = 1;
1904
dfef84fc
MCC
1905 if (pin_num <= 1) {
1906 *pTranslatedpin_num = 0;
7c4ca79f
US
1907 *pGroupNum = 9;
1908 *pGroupCfg = 2;
dfef84fc
MCC
1909 } else if (pin_num >= 2 && pin_num <= 6) {
1910 *pTranslatedpin_num = 2;
7c4ca79f
US
1911 *pGroupNum = 0;
1912 *pGroupCfg = 2;
dfef84fc
MCC
1913 } else if (pin_num >= 7 && pin_num <= 11) {
1914 *pTranslatedpin_num = 7;
7c4ca79f 1915 *pGroupNum = 1;
dfef84fc
MCC
1916 } else if (pin_num >= 12 && pin_num <= 15) {
1917 *pTranslatedpin_num = 12;
7c4ca79f
US
1918 *pGroupNum = 2;
1919 *pGroupCfg = 3;
dfef84fc
MCC
1920 } else if (pin_num == 16) {
1921 *pTranslatedpin_num = 16;
7c4ca79f 1922 *pGroupNum = 23;
dfef84fc
MCC
1923 } else if (pin_num >= 17 && pin_num <= 24) {
1924 *pTranslatedpin_num = 17;
7c4ca79f 1925 *pGroupNum = 3;
dfef84fc
MCC
1926 } else if (pin_num == 25) {
1927 *pTranslatedpin_num = 25;
7c4ca79f 1928 *pGroupNum = 6;
dfef84fc
MCC
1929 } else if (pin_num >= 26 && pin_num <= 28) {
1930 *pTranslatedpin_num = 26;
7c4ca79f 1931 *pGroupNum = 4;
dfef84fc
MCC
1932 } else if (pin_num == 29) {
1933 *pTranslatedpin_num = 29;
7c4ca79f
US
1934 *pGroupNum = 5;
1935 *pGroupCfg = 2;
dfef84fc
MCC
1936 } else if (pin_num == 30) {
1937 *pTranslatedpin_num = 30;
7c4ca79f 1938 *pGroupNum = 8;
dfef84fc
MCC
1939 } else if (pin_num == 31) {
1940 *pTranslatedpin_num = 31;
7c4ca79f
US
1941 *pGroupNum = 17;
1942 } else
1943 return -1;
1944
1945 *pGroupCfg <<= 24;
1946
1947 return 0;
1948}
1949
dfef84fc
MCC
1950int smscore_gpio_configure(struct smscore_device_t *coredev, u8 pin_num,
1951 struct smscore_config_gpio *p_gpio_config) {
7c4ca79f
US
1952
1953 u32 totalLen;
dfef84fc 1954 u32 Translatedpin_num = 0;
be5daa9b 1955 u32 GroupNum = 0;
7c4ca79f
US
1956 u32 ElectricChar;
1957 u32 groupCfg;
1958 void *buffer;
1959 int rc;
1960
1961 struct SetGpioMsg {
dfef84fc 1962 struct sms_msg_hdr x_msg_header;
7c4ca79f
US
1963 u32 msgData[6];
1964 } *pMsg;
1965
1966
dfef84fc 1967 if (pin_num > MAX_GPIO_PIN_NUMBER)
7c4ca79f
US
1968 return -EINVAL;
1969
dfef84fc 1970 if (p_gpio_config == NULL)
7c4ca79f
US
1971 return -EINVAL;
1972
dfef84fc 1973 totalLen = sizeof(struct sms_msg_hdr) + (sizeof(u32) * 6);
7c4ca79f
US
1974
1975 buffer = kmalloc(totalLen + SMS_DMA_ALIGNMENT,
1976 GFP_KERNEL | GFP_DMA);
1977 if (!buffer)
1978 return -ENOMEM;
1979
1980 pMsg = (struct SetGpioMsg *) SMS_ALIGN_ADDRESS(buffer);
1981
dfef84fc
MCC
1982 pMsg->x_msg_header.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
1983 pMsg->x_msg_header.msg_dst_id = HIF_TASK;
1984 pMsg->x_msg_header.msg_flags = 0;
1985 pMsg->x_msg_header.msg_length = (u16) totalLen;
1986 pMsg->msgData[0] = pin_num;
7c4ca79f
US
1987
1988 if (!(coredev->device_flags & SMS_DEVICE_FAMILY2)) {
dfef84fc
MCC
1989 pMsg->x_msg_header.msg_type = MSG_SMS_GPIO_CONFIG_REQ;
1990 if (GetGpioPinParams(pin_num, &Translatedpin_num, &GroupNum,
b46d37e6
JS
1991 &groupCfg) != 0) {
1992 rc = -EINVAL;
1993 goto free;
1994 }
7c4ca79f 1995
dfef84fc 1996 pMsg->msgData[1] = Translatedpin_num;
7c4ca79f 1997 pMsg->msgData[2] = GroupNum;
dfef84fc
MCC
1998 ElectricChar = (p_gpio_config->pullupdown)
1999 | (p_gpio_config->inputcharacteristics << 2)
2000 | (p_gpio_config->outputslewrate << 3)
2001 | (p_gpio_config->outputdriving << 4);
7c4ca79f 2002 pMsg->msgData[3] = ElectricChar;
dfef84fc 2003 pMsg->msgData[4] = p_gpio_config->direction;
7c4ca79f
US
2004 pMsg->msgData[5] = groupCfg;
2005 } else {
dfef84fc
MCC
2006 pMsg->x_msg_header.msg_type = MSG_SMS_GPIO_CONFIG_EX_REQ;
2007 pMsg->msgData[1] = p_gpio_config->pullupdown;
2008 pMsg->msgData[2] = p_gpio_config->outputslewrate;
2009 pMsg->msgData[3] = p_gpio_config->outputdriving;
2010 pMsg->msgData[4] = p_gpio_config->direction;
7c4ca79f
US
2011 pMsg->msgData[5] = 0;
2012 }
2013
7c4ca79f
US
2014 rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
2015 &coredev->gpio_configuration_done);
2016
2017 if (rc != 0) {
2018 if (rc == -ETIME)
2019 sms_err("smscore_gpio_configure timeout");
2020 else
2021 sms_err("smscore_gpio_configure error");
2022 }
b46d37e6 2023free:
7c4ca79f
US
2024 kfree(buffer);
2025
2026 return rc;
2027}
2028
dfef84fc
MCC
2029int smscore_gpio_set_level(struct smscore_device_t *coredev, u8 pin_num,
2030 u8 new_level) {
7c4ca79f
US
2031
2032 u32 totalLen;
2033 int rc;
2034 void *buffer;
2035
2036 struct SetGpioMsg {
dfef84fc 2037 struct sms_msg_hdr x_msg_header;
7c4ca79f
US
2038 u32 msgData[3]; /* keep it 3 ! */
2039 } *pMsg;
2040
dfef84fc 2041 if ((new_level > 1) || (pin_num > MAX_GPIO_PIN_NUMBER))
7c4ca79f
US
2042 return -EINVAL;
2043
dfef84fc 2044 totalLen = sizeof(struct sms_msg_hdr) +
7c4ca79f
US
2045 (3 * sizeof(u32)); /* keep it 3 ! */
2046
2047 buffer = kmalloc(totalLen + SMS_DMA_ALIGNMENT,
2048 GFP_KERNEL | GFP_DMA);
2049 if (!buffer)
2050 return -ENOMEM;
2051
2052 pMsg = (struct SetGpioMsg *) SMS_ALIGN_ADDRESS(buffer);
2053
dfef84fc
MCC
2054 pMsg->x_msg_header.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
2055 pMsg->x_msg_header.msg_dst_id = HIF_TASK;
2056 pMsg->x_msg_header.msg_flags = 0;
2057 pMsg->x_msg_header.msg_type = MSG_SMS_GPIO_SET_LEVEL_REQ;
2058 pMsg->x_msg_header.msg_length = (u16) totalLen;
2059 pMsg->msgData[0] = pin_num;
2060 pMsg->msgData[1] = new_level;
7c4ca79f
US
2061
2062 /* Send message to SMS */
7c4ca79f
US
2063 rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
2064 &coredev->gpio_set_level_done);
2065
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");
2071 }
2072 kfree(buffer);
2073
2074 return rc;
2075}
2076
dfef84fc 2077int smscore_gpio_get_level(struct smscore_device_t *coredev, u8 pin_num,
7c4ca79f
US
2078 u8 *level) {
2079
2080 u32 totalLen;
2081 int rc;
2082 void *buffer;
2083
2084 struct SetGpioMsg {
dfef84fc 2085 struct sms_msg_hdr x_msg_header;
7c4ca79f
US
2086 u32 msgData[2];
2087 } *pMsg;
2088
2089
dfef84fc 2090 if (pin_num > MAX_GPIO_PIN_NUMBER)
7c4ca79f
US
2091 return -EINVAL;
2092
dfef84fc 2093 totalLen = sizeof(struct sms_msg_hdr) + (2 * sizeof(u32));
7c4ca79f
US
2094
2095 buffer = kmalloc(totalLen + SMS_DMA_ALIGNMENT,
2096 GFP_KERNEL | GFP_DMA);
2097 if (!buffer)
2098 return -ENOMEM;
2099
2100 pMsg = (struct SetGpioMsg *) SMS_ALIGN_ADDRESS(buffer);
2101
dfef84fc
MCC
2102 pMsg->x_msg_header.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
2103 pMsg->x_msg_header.msg_dst_id = HIF_TASK;
2104 pMsg->x_msg_header.msg_flags = 0;
2105 pMsg->x_msg_header.msg_type = MSG_SMS_GPIO_GET_LEVEL_REQ;
2106 pMsg->x_msg_header.msg_length = (u16) totalLen;
2107 pMsg->msgData[0] = pin_num;
7c4ca79f
US
2108 pMsg->msgData[1] = 0;
2109
2110 /* Send message to SMS */
7c4ca79f
US
2111 rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
2112 &coredev->gpio_get_level_done);
2113
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");
2119 }
2120 kfree(buffer);
2121
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'
2124 */
2125 *level = coredev->gpio_get_res;
2126
2127 return rc;
2128}
2129
c5e0bd1a 2130static int __init smscore_module_init(void)
2e5c1ec8 2131{
c6465799 2132 int rc = 0;
2e5c1ec8
MK
2133
2134 INIT_LIST_HEAD(&g_smscore_notifyees);
2135 INIT_LIST_HEAD(&g_smscore_devices);
2136 kmutex_init(&g_smscore_deviceslock);
2137
2138 INIT_LIST_HEAD(&g_smscore_registry);
2139 kmutex_init(&g_smscore_registrylock);
2140
2e5c1ec8
MK
2141 return rc;
2142}
2143
c5e0bd1a 2144static void __exit smscore_module_exit(void)
2e5c1ec8 2145{
2e5c1ec8 2146 kmutex_lock(&g_smscore_deviceslock);
82237416 2147 while (!list_empty(&g_smscore_notifyees)) {
18245e18
MK
2148 struct smscore_device_notifyee_t *notifyee =
2149 (struct smscore_device_notifyee_t *)
2150 g_smscore_notifyees.next;
2e5c1ec8
MK
2151
2152 list_del(&notifyee->entry);
2153 kfree(notifyee);
2154 }
2155 kmutex_unlock(&g_smscore_deviceslock);
2156
2157 kmutex_lock(&g_smscore_registrylock);
82237416 2158 while (!list_empty(&g_smscore_registry)) {
18245e18
MK
2159 struct smscore_registry_entry_t *entry =
2160 (struct smscore_registry_entry_t *)
2161 g_smscore_registry.next;
2e5c1ec8
MK
2162
2163 list_del(&entry->entry);
2164 kfree(entry);
2165 }
2166 kmutex_unlock(&g_smscore_registrylock);
2167
a0c0abcb 2168 sms_debug("");
2e5c1ec8
MK
2169}
2170
2171module_init(smscore_module_init);
2172module_exit(smscore_module_exit);
2173
e0f14c25
US
2174MODULE_DESCRIPTION("Siano MDTV Core module");
2175MODULE_AUTHOR("Siano Mobile Silicon, Inc. (uris@siano-ms.com)");
2e5c1ec8 2176MODULE_LICENSE("GPL");
c8b8fdb3
MCC
2177
2178/* This should match what's defined at smscoreapi.h */
2179MODULE_FIRMWARE(SMS_FW_ATSC_DENVER);
2180MODULE_FIRMWARE(SMS_FW_CMMB_MING_APP);
2181MODULE_FIRMWARE(SMS_FW_CMMB_VEGA_12MHZ);
2182MODULE_FIRMWARE(SMS_FW_CMMB_VENICE_12MHZ);
2183MODULE_FIRMWARE(SMS_FW_DVBH_RIO);
2184MODULE_FIRMWARE(SMS_FW_DVB_NOVA_12MHZ_B0);
2185MODULE_FIRMWARE(SMS_FW_DVB_NOVA_12MHZ);
2186MODULE_FIRMWARE(SMS_FW_DVB_RIO);
2187MODULE_FIRMWARE(SMS_FW_FM_RADIO);
2188MODULE_FIRMWARE(SMS_FW_FM_RADIO_RIO);
2189MODULE_FIRMWARE(SMS_FW_DVBT_HCW_55XXX);
2190MODULE_FIRMWARE(SMS_FW_ISDBT_HCW_55XXX);
2191MODULE_FIRMWARE(SMS_FW_ISDBT_NOVA_12MHZ_B0);
2192MODULE_FIRMWARE(SMS_FW_ISDBT_NOVA_12MHZ);
2193MODULE_FIRMWARE(SMS_FW_ISDBT_PELE);
2194MODULE_FIRMWARE(SMS_FW_ISDBT_RIO);
2195MODULE_FIRMWARE(SMS_FW_DVBT_NOVA_A);
2196MODULE_FIRMWARE(SMS_FW_DVBT_NOVA_B);
2197MODULE_FIRMWARE(SMS_FW_DVBT_STELLAR);
2198MODULE_FIRMWARE(SMS_FW_TDMB_DENVER);
2199MODULE_FIRMWARE(SMS_FW_TDMB_NOVA_12MHZ_B0);
2200MODULE_FIRMWARE(SMS_FW_TDMB_NOVA_12MHZ);
This page took 0.522489 seconds and 5 git commands to generate.