]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/media/common/siano/smscoreapi.c
[media] siano: Configure board's mtu and xtal
[mirror_ubuntu-bionic-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
e5d218ee 493 return -EINVAL;
f17407a8 494}
2e5c1ec8 495
e5d218ee 496static void smscore_registry_setmode(char *devpath, int mode)
82237416 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{
e5d218ee
MCC
636 struct smscore_buffer_t *cb;
637
638 cb = kzalloc(sizeof(struct smscore_buffer_t), GFP_KERNEL);
82237416 639 if (!cb) {
e5d218ee 640 sms_info("kzalloc(...) failed");
2e5c1ec8
MK
641 return NULL;
642 }
643
644 cb->p = buffer;
494d24c5 645 cb->offset_in_common = buffer - (u8 *) common_buffer;
2e5c1ec8
MK
646 cb->phys = common_buffer_phys + cb->offset_in_common;
647
648 return cb;
649}
650
651/**
82237416
MK
652 * creates coredev object for a device, prepares buffers,
653 * creates buffer mappings, notifies registered hotplugs about new device.
2e5c1ec8 654 *
59bf6b8e
MK
655 * @param params device pointer to struct with device specific parameters
656 * and handlers
2e5c1ec8
MK
657 * @param coredev pointer to a value that receives created coredev object
658 *
659 * @return 0 on success, <0 on error.
660 */
18245e18
MK
661int smscore_register_device(struct smsdevice_params_t *params,
662 struct smscore_device_t **coredev)
2e5c1ec8 663{
18245e18 664 struct smscore_device_t *dev;
2e5c1ec8
MK
665 u8 *buffer;
666
18245e18 667 dev = kzalloc(sizeof(struct smscore_device_t), GFP_KERNEL);
82237416 668 if (!dev) {
a0c0abcb 669 sms_info("kzalloc(...) failed");
2e5c1ec8
MK
670 return -ENOMEM;
671 }
672
82237416 673 /* init list entry so it could be safe in smscore_unregister_device */
2e5c1ec8
MK
674 INIT_LIST_HEAD(&dev->entry);
675
82237416 676 /* init queues */
2e5c1ec8 677 INIT_LIST_HEAD(&dev->clients);
2e5c1ec8
MK
678 INIT_LIST_HEAD(&dev->buffers);
679
82237416 680 /* init locks */
2e5c1ec8
MK
681 spin_lock_init(&dev->clientslock);
682 spin_lock_init(&dev->bufferslock);
683
82237416 684 /* init completion events */
2e5c1ec8
MK
685 init_completion(&dev->version_ex_done);
686 init_completion(&dev->data_download_done);
018b0c6f 687 init_completion(&dev->data_validity_done);
2e5c1ec8
MK
688 init_completion(&dev->trigger_done);
689 init_completion(&dev->init_device_done);
690 init_completion(&dev->reload_start_done);
691 init_completion(&dev->resume_done);
34601caa
US
692 init_completion(&dev->gpio_configuration_done);
693 init_completion(&dev->gpio_set_level_done);
694 init_completion(&dev->gpio_get_level_done);
a804800a 695 init_completion(&dev->ir_init_done);
2e5c1ec8 696
a9349315
US
697 /* Buffer management */
698 init_waitqueue_head(&dev->buffer_mng_waitq);
699
82237416 700 /* alloc common buffer */
2e5c1ec8 701 dev->common_buffer_size = params->buffer_size * params->num_buffers;
82237416
MK
702 dev->common_buffer = dma_alloc_coherent(NULL, dev->common_buffer_size,
703 &dev->common_buffer_phys,
704 GFP_KERNEL | GFP_DMA);
705 if (!dev->common_buffer) {
2e5c1ec8
MK
706 smscore_unregister_device(dev);
707 return -ENOMEM;
708 }
709
82237416
MK
710 /* prepare dma buffers */
711 for (buffer = dev->common_buffer;
712 dev->num_buffers < params->num_buffers;
fa830e8a 713 dev->num_buffers++, buffer += params->buffer_size) {
e5d218ee
MCC
714 struct smscore_buffer_t *cb;
715
716 cb = smscore_createbuffer(buffer, dev->common_buffer,
717 dev->common_buffer_phys);
82237416 718 if (!cb) {
2e5c1ec8
MK
719 smscore_unregister_device(dev);
720 return -ENOMEM;
721 }
722
723 smscore_putbuffer(dev, cb);
724 }
725
a0c0abcb 726 sms_info("allocated %d buffers", dev->num_buffers);
2e5c1ec8
MK
727
728 dev->mode = DEVICE_MODE_NONE;
3ba92d0b 729 dev->board_id = SMS_BOARD_UNKNOWN;
2e5c1ec8
MK
730 dev->context = params->context;
731 dev->device = params->device;
732 dev->setmode_handler = params->setmode_handler;
733 dev->detectmode_handler = params->detectmode_handler;
734 dev->sendrequest_handler = params->sendrequest_handler;
735 dev->preload_handler = params->preload_handler;
736 dev->postload_handler = params->postload_handler;
737
738 dev->device_flags = params->flags;
739 strcpy(dev->devpath, params->devpath);
740
82237416 741 smscore_registry_settype(dev->devpath, params->device_type);
f17407a8 742
82237416 743 /* add device to devices list */
2e5c1ec8
MK
744 kmutex_lock(&g_smscore_deviceslock);
745 list_add(&dev->entry, &g_smscore_devices);
746 kmutex_unlock(&g_smscore_deviceslock);
747
748 *coredev = dev;
749
a0c0abcb 750 sms_info("device %p created", dev);
2e5c1ec8
MK
751
752 return 0;
753}
a0beec8f 754EXPORT_SYMBOL_GPL(smscore_register_device);
2e5c1ec8 755
a804800a
US
756
757static int smscore_sendrequest_and_wait(struct smscore_device_t *coredev,
758 void *buffer, size_t size, struct completion *completion) {
018b0c6f
MCC
759 int rc;
760
761 if (completion == NULL)
762 return -EINVAL;
763 init_completion(completion);
764
765 rc = coredev->sendrequest_handler(coredev->context, buffer, size);
a804800a
US
766 if (rc < 0) {
767 sms_info("sendrequest returned error %d", rc);
768 return rc;
769 }
770
771 return wait_for_completion_timeout(completion,
772 msecs_to_jiffies(SMS_PROTOCOL_MAX_RAOUNDTRIP_MS)) ?
773 0 : -ETIME;
774}
775
776/**
777 * Starts & enables IR operations
778 *
779 * @return 0 on success, < 0 on error.
780 */
781static int smscore_init_ir(struct smscore_device_t *coredev)
782{
783 int ir_io;
784 int rc;
785 void *buffer;
786
d8b4b582 787 coredev->ir.dev = NULL;
a804800a
US
788 ir_io = sms_get_board(smscore_get_board_id(coredev))->board_cfg.ir;
789 if (ir_io) {/* only if IR port exist we use IR sub-module */
790 sms_info("IR loading");
791 rc = sms_ir_init(coredev);
792
793 if (rc != 0)
794 sms_err("Error initialization DTV IR sub-module");
795 else {
796 buffer = kmalloc(sizeof(struct SmsMsgData_ST2) +
797 SMS_DMA_ALIGNMENT,
798 GFP_KERNEL | GFP_DMA);
799 if (buffer) {
800 struct SmsMsgData_ST2 *msg =
801 (struct SmsMsgData_ST2 *)
802 SMS_ALIGN_ADDRESS(buffer);
803
804 SMS_INIT_MSG(&msg->xMsgHeader,
805 MSG_SMS_START_IR_REQ,
806 sizeof(struct SmsMsgData_ST2));
807 msg->msgData[0] = coredev->ir.controller;
808 msg->msgData[1] = coredev->ir.timeout;
809
810 smsendian_handle_tx_message(
811 (struct SmsMsgHdr_ST2 *)msg);
812 rc = smscore_sendrequest_and_wait(coredev, msg,
813 msg->xMsgHeader. msgLength,
814 &coredev->ir_init_done);
815
816 kfree(buffer);
817 } else
818 sms_err
819 ("Sending IR initialization message failed");
820 }
821 } else
822 sms_info("IR port has not been detected");
823
824 return 0;
825}
826
dfbf021c
MCC
827/**
828 * configures device features according to board configuration structure.
829 *
830 * @param coredev pointer to a coredev object returned by
831 * smscore_register_device
832 *
833 * @return 0 on success, <0 on error.
834 */
835int smscore_configure_board(struct smscore_device_t *coredev)
836{
837 struct sms_board *board;
838
839 board = sms_get_board(coredev->board_id);
840 if (!board) {
841 sms_err("no board configuration exist.");
842 return -EINVAL;
843 }
844
845 if (board->mtu) {
846 struct SmsMsgData_ST MtuMsg;
847 sms_debug("set max transmit unit %d", board->mtu);
848
849 MtuMsg.xMsgHeader.msgSrcId = 0;
850 MtuMsg.xMsgHeader.msgDstId = HIF_TASK;
851 MtuMsg.xMsgHeader.msgFlags = 0;
852 MtuMsg.xMsgHeader.msgType = MSG_SMS_SET_MAX_TX_MSG_LEN_REQ;
853 MtuMsg.xMsgHeader.msgLength = sizeof(MtuMsg);
854 MtuMsg.msgData[0] = board->mtu;
855
856 smsendian_handle_tx_message((struct SmsMsgHdr_ST *)&MtuMsg);
857 coredev->sendrequest_handler(coredev->context, &MtuMsg,
858 sizeof(MtuMsg));
859 }
860
861 if (board->crystal) {
862 struct SmsMsgData_ST CrysMsg;
863 sms_debug("set crystal value %d", board->crystal);
864
865 SMS_INIT_MSG(&CrysMsg.xMsgHeader,
866 MSG_SMS_NEW_CRYSTAL_REQ,
867 sizeof(CrysMsg));
868 CrysMsg.msgData[0] = board->crystal;
869
870 smsendian_handle_tx_message((struct SmsMsgHdr_S *)&CrysMsg);
871 coredev->sendrequest_handler(coredev->context, &CrysMsg,
872 sizeof(CrysMsg));
873 }
874
875 return 0;
876}
877
2e5c1ec8
MK
878/**
879 * sets initial device mode and notifies client hotplugs that device is ready
880 *
59bf6b8e
MK
881 * @param coredev pointer to a coredev object returned by
882 * smscore_register_device
2e5c1ec8
MK
883 *
884 * @return 0 on success, <0 on error.
885 */
18245e18 886int smscore_start_device(struct smscore_device_t *coredev)
2e5c1ec8 887{
59bf6b8e
MK
888 int rc = smscore_set_device_mode(
889 coredev, smscore_registry_getmode(coredev->devpath));
82237416 890 if (rc < 0) {
a0c0abcb 891 sms_info("set device mode faile , rc %d", rc);
2e5c1ec8 892 return rc;
f17407a8 893 }
dfbf021c
MCC
894 rc = smscore_configure_board(coredev);
895 if (rc < 0) {
896 sms_info("configure board failed , rc %d", rc);
897 return rc;
898 }
2e5c1ec8
MK
899
900 kmutex_lock(&g_smscore_deviceslock);
901
902 rc = smscore_notify_callbacks(coredev, coredev->device, 1);
a804800a 903 smscore_init_ir(coredev);
2e5c1ec8 904
a0c0abcb 905 sms_info("device %p started, rc %d", coredev, rc);
2e5c1ec8
MK
906
907 kmutex_unlock(&g_smscore_deviceslock);
908
909 return rc;
910}
a0beec8f 911EXPORT_SYMBOL_GPL(smscore_start_device);
2e5c1ec8 912
2e5c1ec8 913
0c071f37
MK
914static int smscore_load_firmware_family2(struct smscore_device_t *coredev,
915 void *buffer, size_t size)
2e5c1ec8 916{
18245e18 917 struct SmsFirmware_ST *firmware = (struct SmsFirmware_ST *) buffer;
018b0c6f
MCC
918 struct SmsMsgData_ST4 *msg;
919 u32 mem_address, calc_checksum = 0;
920 u32 i, *ptr;
a83ccdd6 921 u8 *payload = firmware->Payload;
2e5c1ec8 922 int rc = 0;
01abc0b0
US
923 firmware->StartAddress = le32_to_cpu(firmware->StartAddress);
924 firmware->Length = le32_to_cpu(firmware->Length);
925
926 mem_address = firmware->StartAddress;
2e5c1ec8 927
a0c0abcb
MK
928 sms_info("loading FW to addr 0x%x size %d",
929 mem_address, firmware->Length);
82237416 930 if (coredev->preload_handler) {
2e5c1ec8
MK
931 rc = coredev->preload_handler(coredev->context);
932 if (rc < 0)
933 return rc;
934 }
935
82237416 936 /* PAGE_SIZE buffer shall be enough and dma aligned */
e080842c 937 msg = kmalloc(PAGE_SIZE, GFP_KERNEL | GFP_DMA);
2e5c1ec8
MK
938 if (!msg)
939 return -ENOMEM;
940
82237416 941 if (coredev->mode != DEVICE_MODE_NONE) {
2522dc13 942 sms_debug("sending reload command.");
018b0c6f 943 SMS_INIT_MSG(&msg->xMsgHeader, MSG_SW_RELOAD_START_REQ,
18245e18 944 sizeof(struct SmsMsgHdr_ST));
82237416 945 rc = smscore_sendrequest_and_wait(coredev, msg,
018b0c6f 946 msg->xMsgHeader.msgLength,
82237416 947 &coredev->reload_start_done);
018b0c6f
MCC
948 if (rc < 0) {
949 sms_err("device reload failed, rc %d", rc);
950 goto exit_fw_download;
951 }
f0333e3d 952 mem_address = *(u32 *) &payload[20];
2e5c1ec8
MK
953 }
954
018b0c6f
MCC
955 for (i = 0, ptr = (u32 *)firmware->Payload; i < firmware->Length/4 ;
956 i++, ptr++)
957 calc_checksum += *ptr;
958
fa830e8a 959 while (size && rc >= 0) {
18245e18
MK
960 struct SmsDataDownload_ST *DataMsg =
961 (struct SmsDataDownload_ST *) msg;
2e5c1ec8
MK
962 int payload_size = min((int) size, SMS_MAX_PAYLOAD_SIZE);
963
018b0c6f 964 SMS_INIT_MSG(&msg->xMsgHeader, MSG_SMS_DATA_DOWNLOAD_REQ,
18245e18 965 (u16)(sizeof(struct SmsMsgHdr_ST) +
f0333e3d 966 sizeof(u32) + payload_size));
2e5c1ec8
MK
967
968 DataMsg->MemAddr = mem_address;
969 memcpy(DataMsg->Payload, payload, payload_size);
970
018b0c6f 971 rc = smscore_sendrequest_and_wait(coredev, DataMsg,
59bf6b8e
MK
972 DataMsg->xMsgHeader.msgLength,
973 &coredev->data_download_done);
2e5c1ec8
MK
974
975 payload += payload_size;
976 size -= payload_size;
977 mem_address += payload_size;
978 }
979
018b0c6f
MCC
980 if (rc < 0)
981 goto exit_fw_download;
982
983 sms_err("sending MSG_SMS_DATA_VALIDITY_REQ expecting 0x%x",
984 calc_checksum);
985 SMS_INIT_MSG(&msg->xMsgHeader, MSG_SMS_DATA_VALIDITY_REQ,
986 sizeof(msg->xMsgHeader) +
987 sizeof(u32) * 3);
988 msg->msgData[0] = firmware->StartAddress;
989 /* Entry point */
990 msg->msgData[1] = firmware->Length;
991 msg->msgData[2] = 0; /* Regular checksum*/
992 smsendian_handle_tx_message(msg);
993 rc = smscore_sendrequest_and_wait(coredev, msg,
994 msg->xMsgHeader.msgLength,
995 &coredev->data_validity_done);
996 if (rc < 0)
997 goto exit_fw_download;
998
999 if (coredev->mode == DEVICE_MODE_NONE) {
1000 struct SmsMsgData_ST *TriggerMsg =
1001 (struct SmsMsgData_ST *) msg;
1002
1003 sms_debug("sending MSG_SMS_SWDOWNLOAD_TRIGGER_REQ");
1004 SMS_INIT_MSG(&msg->xMsgHeader,
1005 MSG_SMS_SWDOWNLOAD_TRIGGER_REQ,
1006 sizeof(struct SmsMsgHdr_ST) +
1007 sizeof(u32) * 5);
1008
1009 TriggerMsg->msgData[0] = firmware->StartAddress;
1010 /* Entry point */
1011 TriggerMsg->msgData[1] = 6; /* Priority */
1012 TriggerMsg->msgData[2] = 0x200; /* Stack size */
1013 TriggerMsg->msgData[3] = 0; /* Parameter */
1014 TriggerMsg->msgData[4] = 4; /* Task ID */
1015
1016 smsendian_handle_tx_message((struct SmsMsgHdr_S *)msg);
1017 rc = smscore_sendrequest_and_wait(coredev, TriggerMsg,
59bf6b8e
MK
1018 TriggerMsg->xMsgHeader.msgLength,
1019 &coredev->trigger_done);
018b0c6f
MCC
1020 } else {
1021 SMS_INIT_MSG(&msg->xMsgHeader, MSG_SW_RELOAD_EXEC_REQ,
1022 sizeof(struct SmsMsgHdr_ST));
1023 smsendian_handle_tx_message((struct SmsMsgHdr_S *)msg);
1024 rc = coredev->sendrequest_handler(coredev->context, msg,
1025 msg->xMsgHeader.msgLength);
2e5c1ec8
MK
1026 }
1027
018b0c6f
MCC
1028 if (rc < 0)
1029 goto exit_fw_download;
1030
1031 /*
1032 * backward compatibility - wait to device_ready_done for
1033 * not more than 400 ms
1034 */
1035 msleep(400);
1036
1037exit_fw_download:
2e5c1ec8
MK
1038 kfree(msg);
1039
1e19c21e
MCC
1040 if (coredev->postload_handler) {
1041 sms_debug("rc=%d, postload=0x%p", rc, coredev->postload_handler);
1042 if (rc >= 0)
1043 return coredev->postload_handler(coredev->context);
1044 }
1045
1046 sms_debug("rc=%d", rc);
1047 return rc;
2e5c1ec8
MK
1048}
1049
018b0c6f
MCC
1050
1051static char *smscore_get_fw_filename(struct smscore_device_t *coredev,
1052 int mode, int lookup);
1053
2e5c1ec8
MK
1054/**
1055 * loads specified firmware into a buffer and calls device loadfirmware_handler
1056 *
59bf6b8e
MK
1057 * @param coredev pointer to a coredev object returned by
1058 * smscore_register_device
2e5c1ec8
MK
1059 * @param filename null-terminated string specifies firmware file name
1060 * @param loadfirmware_handler device handler that loads firmware
1061 *
1062 * @return 0 on success, <0 on error.
1063 */
0c071f37 1064static int smscore_load_firmware_from_file(struct smscore_device_t *coredev,
018b0c6f 1065 int mode, int lookup,
0c071f37 1066 loadfirmware_t loadfirmware_handler)
2e5c1ec8
MK
1067{
1068 int rc = -ENOENT;
018b0c6f
MCC
1069 u8 *fw_buf;
1070 u32 fw_buf_size;
2e5c1ec8 1071 const struct firmware *fw;
2e5c1ec8 1072
018b0c6f 1073 char *fw_filename = smscore_get_fw_filename(coredev, mode, lookup);
ab7bdb12 1074 sms_debug("Firmware name: %s\n", fw_filename);
018b0c6f
MCC
1075 if (!strcmp(fw_filename, "none"))
1076 return -ENOENT;
1077
1078 if (loadfirmware_handler == NULL && !(coredev->device_flags
1079 & SMS_DEVICE_FAMILY2))
2e5c1ec8
MK
1080 return -EINVAL;
1081
018b0c6f 1082 rc = request_firmware(&fw, fw_filename, coredev->device);
82237416 1083 if (rc < 0) {
018b0c6f 1084 sms_info("failed to open \"%s\"", fw_filename);
2e5c1ec8
MK
1085 return rc;
1086 }
018b0c6f
MCC
1087 sms_info("read fw %s, buffer size=0x%zx", fw_filename, fw->size);
1088 fw_buf = kmalloc(ALIGN(fw->size, SMS_ALLOC_ALIGNMENT),
1089 GFP_KERNEL | GFP_DMA);
1090 if (!fw_buf) {
a0c0abcb 1091 sms_info("failed to allocate firmware buffer");
018b0c6f 1092 return -ENOMEM;
2e5c1ec8 1093 }
018b0c6f
MCC
1094 memcpy(fw_buf, fw->data, fw->size);
1095 fw_buf_size = fw->size;
1096
1097 rc = (coredev->device_flags & SMS_DEVICE_FAMILY2) ?
1098 smscore_load_firmware_family2(coredev, fw_buf, fw_buf_size)
1099 : loadfirmware_handler(coredev->context, fw_buf,
1100 fw_buf_size);
2e5c1ec8 1101
018b0c6f 1102 kfree(fw_buf);
2e5c1ec8
MK
1103 release_firmware(fw);
1104
1105 return rc;
1106}
1107
1108/**
59bf6b8e
MK
1109 * notifies all clients registered with the device, notifies hotplugs,
1110 * frees all buffers and coredev object
2e5c1ec8 1111 *
59bf6b8e
MK
1112 * @param coredev pointer to a coredev object returned by
1113 * smscore_register_device
2e5c1ec8
MK
1114 *
1115 * @return 0 on success, <0 on error.
1116 */
18245e18 1117void smscore_unregister_device(struct smscore_device_t *coredev)
2e5c1ec8 1118{
18245e18 1119 struct smscore_buffer_t *cb;
2e5c1ec8 1120 int num_buffers = 0;
f17407a8 1121 int retry = 0;
2e5c1ec8
MK
1122
1123 kmutex_lock(&g_smscore_deviceslock);
1124
a804800a
US
1125 /* Release input device (IR) resources */
1126 sms_ir_exit(coredev);
1127
2e5c1ec8
MK
1128 smscore_notify_clients(coredev);
1129 smscore_notify_callbacks(coredev, NULL, 0);
1130
82237416
MK
1131 /* at this point all buffers should be back
1132 * onresponse must no longer be called */
2e5c1ec8 1133
82237416 1134 while (1) {
a9349315
US
1135 while (!list_empty(&coredev->buffers)) {
1136 cb = (struct smscore_buffer_t *) coredev->buffers.next;
1137 list_del(&cb->entry);
2e5c1ec8 1138 kfree(cb);
fa830e8a 1139 num_buffers++;
2e5c1ec8 1140 }
2e5c1ec8
MK
1141 if (num_buffers == coredev->num_buffers)
1142 break;
82237416 1143 if (++retry > 10) {
a0c0abcb
MK
1144 sms_info("exiting although "
1145 "not all buffers released.");
f17407a8
MK
1146 break;
1147 }
2e5c1ec8 1148
a0c0abcb 1149 sms_info("waiting for %d buffer(s)",
068d6c0f 1150 coredev->num_buffers - num_buffers);
018b0c6f 1151 kmutex_unlock(&g_smscore_deviceslock);
2e5c1ec8 1152 msleep(100);
018b0c6f 1153 kmutex_lock(&g_smscore_deviceslock);
2e5c1ec8
MK
1154 }
1155
a0c0abcb 1156 sms_info("freed %d buffers", num_buffers);
2e5c1ec8
MK
1157
1158 if (coredev->common_buffer)
82237416 1159 dma_free_coherent(NULL, coredev->common_buffer_size,
a9349315
US
1160 coredev->common_buffer, coredev->common_buffer_phys);
1161
2da8eab9 1162 kfree(coredev->fw_buf);
2e5c1ec8
MK
1163
1164 list_del(&coredev->entry);
1165 kfree(coredev);
1166
1167 kmutex_unlock(&g_smscore_deviceslock);
1168
a0c0abcb 1169 sms_info("device %p destroyed", coredev);
2e5c1ec8 1170}
a0beec8f 1171EXPORT_SYMBOL_GPL(smscore_unregister_device);
2e5c1ec8 1172
0c071f37 1173static int smscore_detect_mode(struct smscore_device_t *coredev)
2e5c1ec8 1174{
18245e18 1175 void *buffer = kmalloc(sizeof(struct SmsMsgHdr_ST) + SMS_DMA_ALIGNMENT,
82237416 1176 GFP_KERNEL | GFP_DMA);
18245e18
MK
1177 struct SmsMsgHdr_ST *msg =
1178 (struct SmsMsgHdr_ST *) SMS_ALIGN_ADDRESS(buffer);
2e5c1ec8
MK
1179 int rc;
1180
1181 if (!buffer)
1182 return -ENOMEM;
1183
18245e18
MK
1184 SMS_INIT_MSG(msg, MSG_SMS_GET_VERSION_EX_REQ,
1185 sizeof(struct SmsMsgHdr_ST));
2e5c1ec8 1186
82237416
MK
1187 rc = smscore_sendrequest_and_wait(coredev, msg, msg->msgLength,
1188 &coredev->version_ex_done);
1189 if (rc == -ETIME) {
a0c0abcb 1190 sms_err("MSG_SMS_GET_VERSION_EX_REQ failed first try");
2e5c1ec8 1191
82237416
MK
1192 if (wait_for_completion_timeout(&coredev->resume_done,
1193 msecs_to_jiffies(5000))) {
59bf6b8e
MK
1194 rc = smscore_sendrequest_and_wait(
1195 coredev, msg, msg->msgLength,
1196 &coredev->version_ex_done);
2e5c1ec8 1197 if (rc < 0)
a0c0abcb
MK
1198 sms_err("MSG_SMS_GET_VERSION_EX_REQ failed "
1199 "second try, rc %d", rc);
82237416 1200 } else
2e5c1ec8
MK
1201 rc = -ETIME;
1202 }
1203
1204 kfree(buffer);
1205
1206 return rc;
1207}
1208
0c071f37 1209static char *smscore_fw_lkup[][SMS_NUM_OF_DEVICE_TYPES] = {
018b0c6f
MCC
1210 /*Stellar, NOVA A0, Nova B0, VEGA, VENICE, MING, PELE, RIO, DENVER_1530, DENVER_2160 */
1211 /*DVBT*/
1212 { "none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none", "none", "none", "none", "dvb_rio.inp", "none", "none" },
1213 /*DVBH*/
1214 { "none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none", "none", "none", "none", "dvbh_rio.inp", "none", "none" },
1215 /*TDMB*/
1216 { "none", "tdmb_nova_12mhz.inp", "tdmb_nova_12mhz_b0.inp", "none", "none", "none", "none", "none", "none", "tdmb_denver.inp" },
1217 /*DABIP*/
1218 { "none", "none", "none", "none", "none", "none", "none", "none", "none", "none" },
1219 /*DVBT_BDA*/
1220 { "none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none", "none", "none", "none", "dvb_rio.inp", "none", "none" },
1221 /*ISDBT*/
1222 { "none", "isdbt_nova_12mhz.inp", "isdbt_nova_12mhz_b0.inp", "none", "none", "none", "isdbt_pele.inp", "isdbt_rio.inp", "none", "none" },
1223 /*ISDBT_BDA*/
1224 { "none", "isdbt_nova_12mhz.inp", "isdbt_nova_12mhz_b0.inp", "none", "none", "none", "isdbt_pele.inp", "isdbt_rio.inp", "none", "none" },
1225 /*CMMB*/
1226 { "none", "none", "none", "cmmb_vega_12mhz.inp", "cmmb_venice_12mhz.inp", "cmmb_ming_app.inp", "none", "none", "none", "none" },
1227 /*RAW - not supported*/
1228 { "none", "none", "none", "none", "none", "none", "none", "none", "none", "none" },
1229 /*FM*/
1230 { "none", "none", "fm_radio.inp", "none", "none", "none", "none", "fm_radio_rio.inp", "none", "none" },
1231 /*FM_BDA*/
1232 { "none", "none", "fm_radio.inp", "none", "none", "none", "none", "fm_radio_rio.inp", "none", "none" },
1233 /*ATSC*/
1234 { "none", "none", "none", "none", "none", "none", "none", "none", "atsc_denver.inp", "none" }
2e5c1ec8
MK
1235};
1236
018b0c6f
MCC
1237/**
1238 * get firmware file name from one of the two mechanisms : sms_boards or
1239 * smscore_fw_lkup.
1240 * @param coredev pointer to a coredev object returned by
1241 * smscore_register_device
1242 * @param mode requested mode of operation
1243 * @param lookup if 1, always get the fw filename from smscore_fw_lkup
1244 * table. if 0, try first to get from sms_boards
1245 *
1246 * @return 0 on success, <0 on error.
1247 */
1248static char *smscore_get_fw_filename(struct smscore_device_t *coredev,
1249 int mode, int lookup)
02aea4fb 1250{
018b0c6f
MCC
1251 char **fw;
1252 int board_id = smscore_get_board_id(coredev);
e5d218ee
MCC
1253 enum sms_device_type_st type;
1254
1255 type = smscore_registry_gettype(coredev->devpath);
018b0c6f
MCC
1256
1257 if ((board_id == SMS_BOARD_UNKNOWN) || (lookup == 1)) {
1258 sms_debug("trying to get fw name from lookup table mode %d type %d",
1259 mode, type);
1260 return smscore_fw_lkup[mode][type];
1261 }
1262
1263 sms_debug("trying to get fw name from sms_boards board_id %d mode %d",
1264 board_id, mode);
1265 fw = sms_get_board(board_id)->fw;
1266 if (fw == NULL) {
1267 sms_debug("cannot find fw name in sms_boards, getting from lookup table mode %d type %d",
1268 mode, type);
1269 return smscore_fw_lkup[mode][type];
1270 }
1271
1272 if (fw[mode] == NULL) {
1273 sms_debug("cannot find fw name in sms_boards, getting from lookup table mode %d type %d",
1274 mode, type);
1275 return smscore_fw_lkup[mode][type];
1276 }
1277
1278 return fw[mode];
02aea4fb 1279}
f17407a8 1280
2e5c1ec8
MK
1281/**
1282 * calls device handler to change mode of operation
1283 * NOTE: stellar/usb may disconnect when changing mode
1284 *
59bf6b8e
MK
1285 * @param coredev pointer to a coredev object returned by
1286 * smscore_register_device
2e5c1ec8
MK
1287 * @param mode requested mode of operation
1288 *
1289 * @return 0 on success, <0 on error.
1290 */
18245e18 1291int smscore_set_device_mode(struct smscore_device_t *coredev, int mode)
2e5c1ec8 1292{
2e5c1ec8
MK
1293 int rc = 0;
1294
2522dc13 1295 sms_debug("set device mode to %d", mode);
82237416 1296 if (coredev->device_flags & SMS_DEVICE_FAMILY2) {
08b39642 1297 if (mode < DEVICE_MODE_DVBT || mode >= DEVICE_MODE_RAW_TUNER) {
eb250942 1298 sms_err("invalid mode specified %d", mode);
2e5c1ec8
MK
1299 return -EINVAL;
1300 }
1301
f17407a8
MK
1302 smscore_registry_setmode(coredev->devpath, mode);
1303
82237416 1304 if (!(coredev->device_flags & SMS_DEVICE_NOT_READY)) {
2e5c1ec8 1305 rc = smscore_detect_mode(coredev);
82237416 1306 if (rc < 0) {
eb250942 1307 sms_err("mode detect failed %d", rc);
2e5c1ec8 1308 return rc;
82237416 1309 }
f17407a8 1310 }
2e5c1ec8 1311
82237416 1312 if (coredev->mode == mode) {
a0c0abcb 1313 sms_info("device mode %d already set", mode);
2e5c1ec8
MK
1314 return 0;
1315 }
1316
82237416 1317 if (!(coredev->modes_supported & (1 << mode))) {
02aea4fb 1318 rc = smscore_load_firmware_from_file(coredev,
018b0c6f 1319 mode, 0, NULL);
02aea4fb 1320
018b0c6f
MCC
1321 /*
1322 * try again with the default firmware -
1323 * get the fw filename from look-up table
1324 */
1325 if (rc < 0) {
1326 sms_debug("error %d loading firmware, trying again with default firmware",
1327 rc);
02aea4fb 1328 rc = smscore_load_firmware_from_file(coredev,
018b0c6f
MCC
1329 mode, 1,
1330 NULL);
02aea4fb 1331 if (rc < 0) {
018b0c6f
MCC
1332 sms_debug("error %d loading firmware",
1333 rc);
02aea4fb
MK
1334 return rc;
1335 }
82237416 1336 }
018b0c6f
MCC
1337 if (rc >= 0)
1338 sms_info("firmware download success");
82237416 1339 } else {
018b0c6f
MCC
1340 sms_info("mode %d is already supported by running firmware",
1341 mode);
82237416
MK
1342 }
1343 } else {
1344 if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_DVBT_BDA) {
eb250942 1345 sms_err("invalid mode specified %d", mode);
f17407a8
MK
1346 return -EINVAL;
1347 }
1348
1349 smscore_registry_setmode(coredev->devpath, mode);
1350
2e5c1ec8 1351 if (coredev->detectmode_handler)
82237416
MK
1352 coredev->detectmode_handler(coredev->context,
1353 &coredev->mode);
2e5c1ec8
MK
1354
1355 if (coredev->mode != mode && coredev->setmode_handler)
1356 rc = coredev->setmode_handler(coredev->context, mode);
1357 }
1358
82237416 1359 if (rc >= 0) {
018b0c6f 1360 char *buffer;
2e5c1ec8
MK
1361 coredev->mode = mode;
1362 coredev->device_flags &= ~SMS_DEVICE_NOT_READY;
018b0c6f
MCC
1363
1364 buffer = kmalloc(sizeof(struct SmsMsgData_ST) +
1365 SMS_DMA_ALIGNMENT, GFP_KERNEL | GFP_DMA);
1366 if (buffer) {
1367 struct SmsMsgData_ST *msg = (struct SmsMsgData_ST *) SMS_ALIGN_ADDRESS(buffer);
1368
1369 SMS_INIT_MSG(&msg->xMsgHeader, MSG_SMS_INIT_DEVICE_REQ,
1370 sizeof(struct SmsMsgData_ST));
1371 msg->msgData[0] = mode;
1372
1373 rc = smscore_sendrequest_and_wait(
1374 coredev, msg, msg->xMsgHeader.msgLength,
1375 &coredev->init_device_done);
1376
1377 kfree(buffer);
1378 }
2e5c1ec8
MK
1379 }
1380
5d2387e3 1381 if (rc < 0)
eb250942 1382 sms_err("return error code %d.", rc);
e5d218ee
MCC
1383 else
1384 sms_debug("Success setting device mode.");
1385
2e5c1ec8
MK
1386 return rc;
1387}
1388
1389/**
1390 * calls device handler to get current mode of operation
1391 *
59bf6b8e
MK
1392 * @param coredev pointer to a coredev object returned by
1393 * smscore_register_device
2e5c1ec8
MK
1394 *
1395 * @return current mode
1396 */
18245e18 1397int smscore_get_device_mode(struct smscore_device_t *coredev)
2e5c1ec8
MK
1398{
1399 return coredev->mode;
1400}
a0beec8f 1401EXPORT_SYMBOL_GPL(smscore_get_device_mode);
2e5c1ec8 1402
f17407a8
MK
1403/**
1404 * find client by response id & type within the clients list.
1405 * return client handle or NULL.
1406 *
59bf6b8e
MK
1407 * @param coredev pointer to a coredev object returned by
1408 * smscore_register_device
f17407a8 1409 * @param data_type client data type (SMS_DONT_CARE for all types)
82237416 1410 * @param id client id (SMS_DONT_CARE for all id)
f17407a8
MK
1411 *
1412 */
0c071f37
MK
1413static struct
1414smscore_client_t *smscore_find_client(struct smscore_device_t *coredev,
59bf6b8e 1415 int data_type, int id)
2e5c1ec8 1416{
0208c15e
JL
1417 struct list_head *first;
1418 struct smscore_client_t *client;
2e5c1ec8 1419 unsigned long flags;
0208c15e
JL
1420 struct list_head *firstid;
1421 struct smscore_idlist_t *client_id;
2e5c1ec8
MK
1422
1423 spin_lock_irqsave(&coredev->clientslock, flags);
2e5c1ec8 1424 first = &coredev->clients;
0208c15e
JL
1425 list_for_each_entry(client, first, entry) {
1426 firstid = &client->idlist;
1427 list_for_each_entry(client_id, firstid, entry) {
1428 if ((client_id->id == id) &&
1429 (client_id->data_type == data_type ||
1430 (client_id->data_type == 0)))
1431 goto found;
2e5c1ec8
MK
1432 }
1433 }
0208c15e
JL
1434 client = NULL;
1435found:
2e5c1ec8 1436 spin_unlock_irqrestore(&coredev->clientslock, flags);
2e5c1ec8
MK
1437 return client;
1438}
1439
1440/**
1441 * find client by response id/type, call clients onresponse handler
1442 * return buffer to pool on error
1443 *
59bf6b8e
MK
1444 * @param coredev pointer to a coredev object returned by
1445 * smscore_register_device
2e5c1ec8
MK
1446 * @param cb pointer to response buffer descriptor
1447 *
1448 */
18245e18 1449void smscore_onresponse(struct smscore_device_t *coredev,
793786d1
US
1450 struct smscore_buffer_t *cb) {
1451 struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *) ((u8 *) cb->p
1452 + cb->offset);
1453 struct smscore_client_t *client;
2e5c1ec8 1454 int rc = -EBUSY;
fbd05c82
MK
1455 static unsigned long last_sample_time; /* = 0; */
1456 static int data_total; /* = 0; */
2e5c1ec8
MK
1457 unsigned long time_now = jiffies_to_msecs(jiffies);
1458
1459 if (!last_sample_time)
1460 last_sample_time = time_now;
1461
fa830e8a 1462 if (time_now - last_sample_time > 10000) {
a0c0abcb 1463 sms_debug("\ndata rate %d bytes/secs",
068d6c0f
MK
1464 (int)((data_total * 1000) /
1465 (time_now - last_sample_time)));
2e5c1ec8
MK
1466
1467 last_sample_time = time_now;
1468 data_total = 0;
1469 }
1470
1471 data_total += cb->size;
793786d1
US
1472 /* Do we need to re-route? */
1473 if ((phdr->msgType == MSG_SMS_HO_PER_SLICES_IND) ||
1474 (phdr->msgType == MSG_SMS_TRANSMISSION_IND)) {
1475 if (coredev->mode == DEVICE_MODE_DVBT_BDA)
1476 phdr->msgDstId = DVBT_BDA_CONTROL_MSG_ID;
1477 }
1478
1479
1480 client = smscore_find_client(coredev, phdr->msgType, phdr->msgDstId);
1481
82237416
MK
1482 /* If no client registered for type & id,
1483 * check for control client where type is not registered */
2e5c1ec8
MK
1484 if (client)
1485 rc = client->onresponse_handler(client->context, cb);
1486
82237416 1487 if (rc < 0) {
faab6820
MCC
1488 smsendian_handle_rx_message((struct SmsMsgData_ST *)phdr);
1489
82237416 1490 switch (phdr->msgType) {
faab6820
MCC
1491 case MSG_SMS_ISDBT_TUNE_RES:
1492 break;
1493 case MSG_SMS_RF_TUNE_RES:
1494 break;
1495 case MSG_SMS_SIGNAL_DETECTED_IND:
1496 break;
1497 case MSG_SMS_NO_SIGNAL_IND:
1498 break;
1499 case MSG_SMS_SPI_INT_LINE_SET_RES:
1500 break;
1501 case MSG_SMS_INTERFACE_LOCK_IND:
1502 break;
1503 case MSG_SMS_INTERFACE_UNLOCK_IND:
1504 break;
82237416 1505 case MSG_SMS_GET_VERSION_EX_RES:
2e5c1ec8 1506 {
18245e18
MK
1507 struct SmsVersionRes_ST *ver =
1508 (struct SmsVersionRes_ST *) phdr;
4c3bdb5e 1509 sms_debug("Firmware id %d prots 0x%x ver %d.%d",
068d6c0f
MK
1510 ver->FirmwareId, ver->SupportedProtocols,
1511 ver->RomVersionMajor, ver->RomVersionMinor);
2e5c1ec8 1512
82237416
MK
1513 coredev->mode = ver->FirmwareId == 255 ?
1514 DEVICE_MODE_NONE : ver->FirmwareId;
1515 coredev->modes_supported = ver->SupportedProtocols;
73338395
MCC
1516 coredev->fw_version = ver->RomVersionMajor << 8 |
1517 ver->RomVersionMinor;
2e5c1ec8 1518
82237416
MK
1519 complete(&coredev->version_ex_done);
1520 break;
1521 }
1522 case MSG_SMS_INIT_DEVICE_RES:
82237416
MK
1523 complete(&coredev->init_device_done);
1524 break;
1525 case MSG_SW_RELOAD_START_RES:
82237416
MK
1526 complete(&coredev->reload_start_done);
1527 break;
018b0c6f
MCC
1528 case MSG_SMS_DATA_VALIDITY_RES:
1529 {
1530 struct SmsMsgData_ST *validity = (struct SmsMsgData_ST *) phdr;
1531
1532 sms_err("MSG_SMS_DATA_VALIDITY_RES, checksum = 0x%x",
1533 validity->msgData[0]);
1534 complete(&coredev->data_validity_done);
1535 break;
1536 }
82237416
MK
1537 case MSG_SMS_DATA_DOWNLOAD_RES:
1538 complete(&coredev->data_download_done);
1539 break;
1540 case MSG_SW_RELOAD_EXEC_RES:
82237416
MK
1541 break;
1542 case MSG_SMS_SWDOWNLOAD_TRIGGER_RES:
82237416
MK
1543 complete(&coredev->trigger_done);
1544 break;
1545 case MSG_SMS_SLEEP_RESUME_COMP_IND:
1546 complete(&coredev->resume_done);
1547 break;
34601caa 1548 case MSG_SMS_GPIO_CONFIG_EX_RES:
34601caa
US
1549 complete(&coredev->gpio_configuration_done);
1550 break;
1551 case MSG_SMS_GPIO_SET_LEVEL_RES:
34601caa
US
1552 complete(&coredev->gpio_set_level_done);
1553 break;
1554 case MSG_SMS_GPIO_GET_LEVEL_RES:
1555 {
1556 u32 *msgdata = (u32 *) phdr;
1557 coredev->gpio_get_res = msgdata[1];
4c3bdb5e 1558 sms_debug("gpio level %d",
34601caa
US
1559 coredev->gpio_get_res);
1560 complete(&coredev->gpio_get_level_done);
1561 break;
1562 }
a804800a
US
1563 case MSG_SMS_START_IR_RES:
1564 complete(&coredev->ir_init_done);
1565 break;
1566 case MSG_SMS_IR_SAMPLES_IND:
1567 sms_ir_event(coredev,
1568 (const char *)
1569 ((char *)phdr
1570 + sizeof(struct SmsMsgHdr_ST)),
1571 (int)phdr->msgLength
1572 - sizeof(struct SmsMsgHdr_ST));
1573 break;
1574
82237416 1575 default:
4c3bdb5e 1576 sms_debug("message not handled.\n");
82237416 1577 break;
2e5c1ec8 1578 }
2e5c1ec8
MK
1579 smscore_putbuffer(coredev, cb);
1580 }
1581}
a0beec8f 1582EXPORT_SYMBOL_GPL(smscore_onresponse);
2e5c1ec8
MK
1583
1584/**
1585 * return pointer to next free buffer descriptor from core pool
1586 *
59bf6b8e
MK
1587 * @param coredev pointer to a coredev object returned by
1588 * smscore_register_device
2e5c1ec8
MK
1589 *
1590 * @return pointer to descriptor on success, NULL on error.
1591 */
3cdadc50 1592
c246ffc2 1593static struct smscore_buffer_t *get_entry(struct smscore_device_t *coredev)
2e5c1ec8 1594{
18245e18 1595 struct smscore_buffer_t *cb = NULL;
2e5c1ec8
MK
1596 unsigned long flags;
1597
1598 spin_lock_irqsave(&coredev->bufferslock, flags);
3cdadc50
RZ
1599 if (!list_empty(&coredev->buffers)) {
1600 cb = (struct smscore_buffer_t *) coredev->buffers.next;
1601 list_del(&cb->entry);
d0a38ce2 1602 }
3cdadc50
RZ
1603 spin_unlock_irqrestore(&coredev->bufferslock, flags);
1604 return cb;
1605}
a9349315 1606
3cdadc50
RZ
1607struct smscore_buffer_t *smscore_getbuffer(struct smscore_device_t *coredev)
1608{
1609 struct smscore_buffer_t *cb = NULL;
2e5c1ec8 1610
3cdadc50 1611 wait_event(coredev->buffer_mng_waitq, (cb = get_entry(coredev)));
2e5c1ec8
MK
1612
1613 return cb;
1614}
a0beec8f 1615EXPORT_SYMBOL_GPL(smscore_getbuffer);
2e5c1ec8
MK
1616
1617/**
1618 * return buffer descriptor to a pool
1619 *
59bf6b8e
MK
1620 * @param coredev pointer to a coredev object returned by
1621 * smscore_register_device
2e5c1ec8
MK
1622 * @param cb pointer buffer descriptor
1623 *
1624 */
18245e18 1625void smscore_putbuffer(struct smscore_device_t *coredev,
a9349315
US
1626 struct smscore_buffer_t *cb) {
1627 wake_up_interruptible(&coredev->buffer_mng_waitq);
2e5c1ec8
MK
1628 list_add_locked(&cb->entry, &coredev->buffers, &coredev->bufferslock);
1629}
a0beec8f 1630EXPORT_SYMBOL_GPL(smscore_putbuffer);
2e5c1ec8 1631
0c071f37
MK
1632static int smscore_validate_client(struct smscore_device_t *coredev,
1633 struct smscore_client_t *client,
1634 int data_type, int id)
2e5c1ec8 1635{
18245e18
MK
1636 struct smscore_idlist_t *listentry;
1637 struct smscore_client_t *registered_client;
2e5c1ec8 1638
82237416 1639 if (!client) {
2522dc13 1640 sms_err("bad parameter.");
d316b5fb 1641 return -EINVAL;
f17407a8
MK
1642 }
1643 registered_client = smscore_find_client(coredev, data_type, id);
fa830e8a 1644 if (registered_client == client)
2e5c1ec8 1645 return 0;
fa830e8a 1646
82237416 1647 if (registered_client) {
2522dc13 1648 sms_err("The msg ID already registered to another client.");
f17407a8
MK
1649 return -EEXIST;
1650 }
18245e18 1651 listentry = kzalloc(sizeof(struct smscore_idlist_t), GFP_KERNEL);
82237416 1652 if (!listentry) {
2522dc13 1653 sms_err("Can't allocate memory for client id.");
2e5c1ec8 1654 return -ENOMEM;
f17407a8
MK
1655 }
1656 listentry->id = id;
1657 listentry->data_type = data_type;
82237416
MK
1658 list_add_locked(&listentry->entry, &client->idlist,
1659 &coredev->clientslock);
2e5c1ec8
MK
1660 return 0;
1661}
1662
1663/**
1664 * creates smsclient object, check that id is taken by another client
1665 *
1666 * @param coredev pointer to a coredev object from clients hotplug
1667 * @param initial_id all messages with this id would be sent to this client
1668 * @param data_type all messages of this type would be sent to this client
ca783736
MK
1669 * @param onresponse_handler client handler that is called to
1670 * process incoming messages
2e5c1ec8
MK
1671 * @param onremove_handler client handler that is called when device is removed
1672 * @param context client-specific context
1673 * @param client pointer to a value that receives created smsclient object
1674 *
1675 * @return 0 on success, <0 on error.
1676 */
18245e18
MK
1677int smscore_register_client(struct smscore_device_t *coredev,
1678 struct smsclient_params_t *params,
1679 struct smscore_client_t **client)
2e5c1ec8 1680{
18245e18 1681 struct smscore_client_t *newclient;
82237416
MK
1682 /* check that no other channel with same parameters exists */
1683 if (smscore_find_client(coredev, params->data_type,
1684 params->initial_id)) {
2522dc13 1685 sms_err("Client already exist.");
2e5c1ec8 1686 return -EEXIST;
f17407a8 1687 }
2e5c1ec8 1688
18245e18 1689 newclient = kzalloc(sizeof(struct smscore_client_t), GFP_KERNEL);
82237416 1690 if (!newclient) {
2522dc13 1691 sms_err("Failed to allocate memory for client.");
f17407a8 1692 return -ENOMEM;
2e5c1ec8
MK
1693 }
1694
82237416 1695 INIT_LIST_HEAD(&newclient->idlist);
2e5c1ec8 1696 newclient->coredev = coredev;
2e5c1ec8
MK
1697 newclient->onresponse_handler = params->onresponse_handler;
1698 newclient->onremove_handler = params->onremove_handler;
1699 newclient->context = params->context;
82237416
MK
1700 list_add_locked(&newclient->entry, &coredev->clients,
1701 &coredev->clientslock);
1702 smscore_validate_client(coredev, newclient, params->data_type,
1703 params->initial_id);
2e5c1ec8 1704 *client = newclient;
2522dc13
MK
1705 sms_debug("%p %d %d", params->context, params->data_type,
1706 params->initial_id);
2e5c1ec8
MK
1707
1708 return 0;
1709}
a0beec8f 1710EXPORT_SYMBOL_GPL(smscore_register_client);
2e5c1ec8
MK
1711
1712/**
1713 * frees smsclient object and all subclients associated with it
1714 *
59bf6b8e
MK
1715 * @param client pointer to smsclient object returned by
1716 * smscore_register_client
2e5c1ec8
MK
1717 *
1718 */
18245e18 1719void smscore_unregister_client(struct smscore_client_t *client)
2e5c1ec8 1720{
18245e18 1721 struct smscore_device_t *coredev = client->coredev;
2e5c1ec8
MK
1722 unsigned long flags;
1723
1724 spin_lock_irqsave(&coredev->clientslock, flags);
1725
2e5c1ec8 1726
82237416 1727 while (!list_empty(&client->idlist)) {
18245e18
MK
1728 struct smscore_idlist_t *identry =
1729 (struct smscore_idlist_t *) client->idlist.next;
82237416
MK
1730 list_del(&identry->entry);
1731 kfree(identry);
2e5c1ec8
MK
1732 }
1733
a0c0abcb 1734 sms_info("%p", client->context);
2e5c1ec8
MK
1735
1736 list_del(&client->entry);
1737 kfree(client);
1738
1739 spin_unlock_irqrestore(&coredev->clientslock, flags);
1740}
a0beec8f 1741EXPORT_SYMBOL_GPL(smscore_unregister_client);
2e5c1ec8
MK
1742
1743/**
1744 * verifies that source id is not taken by another client,
1745 * calls device handler to send requests to the device
1746 *
59bf6b8e
MK
1747 * @param client pointer to smsclient object returned by
1748 * smscore_register_client
2e5c1ec8
MK
1749 * @param buffer pointer to a request buffer
1750 * @param size size (in bytes) of request buffer
1751 *
1752 * @return 0 on success, <0 on error.
1753 */
18245e18
MK
1754int smsclient_sendrequest(struct smscore_client_t *client,
1755 void *buffer, size_t size)
2e5c1ec8 1756{
18245e18
MK
1757 struct smscore_device_t *coredev;
1758 struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *) buffer;
f17407a8
MK
1759 int rc;
1760
82237416 1761 if (client == NULL) {
a0c0abcb 1762 sms_err("Got NULL client");
f17407a8
MK
1763 return -EINVAL;
1764 }
1765
1766 coredev = client->coredev;
2e5c1ec8 1767
82237416
MK
1768 /* check that no other channel with same id exists */
1769 if (coredev == NULL) {
a0c0abcb 1770 sms_err("Got NULL coredev");
f17407a8
MK
1771 return -EINVAL;
1772 }
1773
82237416
MK
1774 rc = smscore_validate_client(client->coredev, client, 0,
1775 phdr->msgSrcId);
2e5c1ec8
MK
1776 if (rc < 0)
1777 return rc;
1778
1779 return coredev->sendrequest_handler(coredev->context, buffer, size);
1780}
a0beec8f 1781EXPORT_SYMBOL_GPL(smsclient_sendrequest);
2e5c1ec8 1782
2e5c1ec8 1783
65155b37 1784/* old GPIO managements implementation */
76052bc8 1785int smscore_configure_gpio(struct smscore_device_t *coredev, u32 pin,
7c4ca79f 1786 struct smscore_config_gpio *pinconfig)
76052bc8
MK
1787{
1788 struct {
1789 struct SmsMsgHdr_ST hdr;
1790 u32 data[6];
1791 } msg;
1792
1793 if (coredev->device_flags & SMS_DEVICE_FAMILY2) {
1794 msg.hdr.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
1795 msg.hdr.msgDstId = HIF_TASK;
1796 msg.hdr.msgFlags = 0;
1797 msg.hdr.msgType = MSG_SMS_GPIO_CONFIG_EX_REQ;
1798 msg.hdr.msgLength = sizeof(msg);
1799
1800 msg.data[0] = pin;
1801 msg.data[1] = pinconfig->pullupdown;
1802
1803 /* Convert slew rate for Nova: Fast(0) = 3 / Slow(1) = 0; */
1804 msg.data[2] = pinconfig->outputslewrate == 0 ? 3 : 0;
1805
1806 switch (pinconfig->outputdriving) {
f82757d9 1807 case SMS_GPIO_OUTPUTDRIVING_S_16mA:
76052bc8
MK
1808 msg.data[3] = 7; /* Nova - 16mA */
1809 break;
f82757d9 1810 case SMS_GPIO_OUTPUTDRIVING_S_12mA:
76052bc8
MK
1811 msg.data[3] = 5; /* Nova - 11mA */
1812 break;
f82757d9 1813 case SMS_GPIO_OUTPUTDRIVING_S_8mA:
76052bc8
MK
1814 msg.data[3] = 3; /* Nova - 7mA */
1815 break;
f82757d9 1816 case SMS_GPIO_OUTPUTDRIVING_S_4mA:
76052bc8
MK
1817 default:
1818 msg.data[3] = 2; /* Nova - 4mA */
1819 break;
1820 }
1821
1822 msg.data[4] = pinconfig->direction;
1823 msg.data[5] = 0;
1824 } else /* TODO: SMS_DEVICE_FAMILY1 */
1825 return -EINVAL;
1826
1827 return coredev->sendrequest_handler(coredev->context,
1828 &msg, sizeof(msg));
1829}
1830
1831int smscore_set_gpio(struct smscore_device_t *coredev, u32 pin, int level)
1832{
1833 struct {
1834 struct SmsMsgHdr_ST hdr;
1835 u32 data[3];
1836 } msg;
1837
1838 if (pin > MAX_GPIO_PIN_NUMBER)
1839 return -EINVAL;
1840
1841 msg.hdr.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
1842 msg.hdr.msgDstId = HIF_TASK;
1843 msg.hdr.msgFlags = 0;
1844 msg.hdr.msgType = MSG_SMS_GPIO_SET_LEVEL_REQ;
1845 msg.hdr.msgLength = sizeof(msg);
1846
1847 msg.data[0] = pin;
1848 msg.data[1] = level ? 1 : 0;
1849 msg.data[2] = 0;
1850
1851 return coredev->sendrequest_handler(coredev->context,
1852 &msg, sizeof(msg));
1853}
1854
3dbda77e 1855/* new GPIO management implementation */
7c4ca79f
US
1856static int GetGpioPinParams(u32 PinNum, u32 *pTranslatedPinNum,
1857 u32 *pGroupNum, u32 *pGroupCfg) {
1858
1859 *pGroupCfg = 1;
1860
f14a2972 1861 if (PinNum <= 1) {
7c4ca79f
US
1862 *pTranslatedPinNum = 0;
1863 *pGroupNum = 9;
1864 *pGroupCfg = 2;
1865 } else if (PinNum >= 2 && PinNum <= 6) {
1866 *pTranslatedPinNum = 2;
1867 *pGroupNum = 0;
1868 *pGroupCfg = 2;
1869 } else if (PinNum >= 7 && PinNum <= 11) {
1870 *pTranslatedPinNum = 7;
1871 *pGroupNum = 1;
1872 } else if (PinNum >= 12 && PinNum <= 15) {
1873 *pTranslatedPinNum = 12;
1874 *pGroupNum = 2;
1875 *pGroupCfg = 3;
1876 } else if (PinNum == 16) {
1877 *pTranslatedPinNum = 16;
1878 *pGroupNum = 23;
1879 } else if (PinNum >= 17 && PinNum <= 24) {
1880 *pTranslatedPinNum = 17;
1881 *pGroupNum = 3;
1882 } else if (PinNum == 25) {
1883 *pTranslatedPinNum = 25;
1884 *pGroupNum = 6;
1885 } else if (PinNum >= 26 && PinNum <= 28) {
1886 *pTranslatedPinNum = 26;
1887 *pGroupNum = 4;
1888 } else if (PinNum == 29) {
1889 *pTranslatedPinNum = 29;
1890 *pGroupNum = 5;
1891 *pGroupCfg = 2;
1892 } else if (PinNum == 30) {
1893 *pTranslatedPinNum = 30;
1894 *pGroupNum = 8;
1895 } else if (PinNum == 31) {
1896 *pTranslatedPinNum = 31;
1897 *pGroupNum = 17;
1898 } else
1899 return -1;
1900
1901 *pGroupCfg <<= 24;
1902
1903 return 0;
1904}
1905
1906int smscore_gpio_configure(struct smscore_device_t *coredev, u8 PinNum,
c31b9fb2 1907 struct smscore_config_gpio *pGpioConfig) {
7c4ca79f
US
1908
1909 u32 totalLen;
be5daa9b
HV
1910 u32 TranslatedPinNum = 0;
1911 u32 GroupNum = 0;
7c4ca79f
US
1912 u32 ElectricChar;
1913 u32 groupCfg;
1914 void *buffer;
1915 int rc;
1916
1917 struct SetGpioMsg {
1918 struct SmsMsgHdr_ST xMsgHeader;
1919 u32 msgData[6];
1920 } *pMsg;
1921
1922
1923 if (PinNum > MAX_GPIO_PIN_NUMBER)
1924 return -EINVAL;
1925
1926 if (pGpioConfig == NULL)
1927 return -EINVAL;
1928
1929 totalLen = sizeof(struct SmsMsgHdr_ST) + (sizeof(u32) * 6);
1930
1931 buffer = kmalloc(totalLen + SMS_DMA_ALIGNMENT,
1932 GFP_KERNEL | GFP_DMA);
1933 if (!buffer)
1934 return -ENOMEM;
1935
1936 pMsg = (struct SetGpioMsg *) SMS_ALIGN_ADDRESS(buffer);
1937
1938 pMsg->xMsgHeader.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
1939 pMsg->xMsgHeader.msgDstId = HIF_TASK;
1940 pMsg->xMsgHeader.msgFlags = 0;
1941 pMsg->xMsgHeader.msgLength = (u16) totalLen;
1942 pMsg->msgData[0] = PinNum;
1943
1944 if (!(coredev->device_flags & SMS_DEVICE_FAMILY2)) {
1945 pMsg->xMsgHeader.msgType = MSG_SMS_GPIO_CONFIG_REQ;
1946 if (GetGpioPinParams(PinNum, &TranslatedPinNum, &GroupNum,
b46d37e6
JS
1947 &groupCfg) != 0) {
1948 rc = -EINVAL;
1949 goto free;
1950 }
7c4ca79f
US
1951
1952 pMsg->msgData[1] = TranslatedPinNum;
1953 pMsg->msgData[2] = GroupNum;
c31b9fb2
MCC
1954 ElectricChar = (pGpioConfig->pullupdown)
1955 | (pGpioConfig->inputcharacteristics << 2)
1956 | (pGpioConfig->outputslewrate << 3)
1957 | (pGpioConfig->outputdriving << 4);
7c4ca79f 1958 pMsg->msgData[3] = ElectricChar;
c31b9fb2 1959 pMsg->msgData[4] = pGpioConfig->direction;
7c4ca79f
US
1960 pMsg->msgData[5] = groupCfg;
1961 } else {
1962 pMsg->xMsgHeader.msgType = MSG_SMS_GPIO_CONFIG_EX_REQ;
c31b9fb2
MCC
1963 pMsg->msgData[1] = pGpioConfig->pullupdown;
1964 pMsg->msgData[2] = pGpioConfig->outputslewrate;
1965 pMsg->msgData[3] = pGpioConfig->outputdriving;
1966 pMsg->msgData[4] = pGpioConfig->direction;
7c4ca79f
US
1967 pMsg->msgData[5] = 0;
1968 }
1969
1970 smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg);
1971 rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
1972 &coredev->gpio_configuration_done);
1973
1974 if (rc != 0) {
1975 if (rc == -ETIME)
1976 sms_err("smscore_gpio_configure timeout");
1977 else
1978 sms_err("smscore_gpio_configure error");
1979 }
b46d37e6 1980free:
7c4ca79f
US
1981 kfree(buffer);
1982
1983 return rc;
1984}
1985
1986int smscore_gpio_set_level(struct smscore_device_t *coredev, u8 PinNum,
1987 u8 NewLevel) {
1988
1989 u32 totalLen;
1990 int rc;
1991 void *buffer;
1992
1993 struct SetGpioMsg {
1994 struct SmsMsgHdr_ST xMsgHeader;
1995 u32 msgData[3]; /* keep it 3 ! */
1996 } *pMsg;
1997
f78729b4 1998 if ((NewLevel > 1) || (PinNum > MAX_GPIO_PIN_NUMBER))
7c4ca79f
US
1999 return -EINVAL;
2000
2001 totalLen = sizeof(struct SmsMsgHdr_ST) +
2002 (3 * sizeof(u32)); /* keep it 3 ! */
2003
2004 buffer = kmalloc(totalLen + SMS_DMA_ALIGNMENT,
2005 GFP_KERNEL | GFP_DMA);
2006 if (!buffer)
2007 return -ENOMEM;
2008
2009 pMsg = (struct SetGpioMsg *) SMS_ALIGN_ADDRESS(buffer);
2010
2011 pMsg->xMsgHeader.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
2012 pMsg->xMsgHeader.msgDstId = HIF_TASK;
2013 pMsg->xMsgHeader.msgFlags = 0;
2014 pMsg->xMsgHeader.msgType = MSG_SMS_GPIO_SET_LEVEL_REQ;
2015 pMsg->xMsgHeader.msgLength = (u16) totalLen;
2016 pMsg->msgData[0] = PinNum;
2017 pMsg->msgData[1] = NewLevel;
2018
2019 /* Send message to SMS */
2020 smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg);
2021 rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
2022 &coredev->gpio_set_level_done);
2023
2024 if (rc != 0) {
2025 if (rc == -ETIME)
2026 sms_err("smscore_gpio_set_level timeout");
2027 else
2028 sms_err("smscore_gpio_set_level error");
2029 }
2030 kfree(buffer);
2031
2032 return rc;
2033}
2034
2035int smscore_gpio_get_level(struct smscore_device_t *coredev, u8 PinNum,
2036 u8 *level) {
2037
2038 u32 totalLen;
2039 int rc;
2040 void *buffer;
2041
2042 struct SetGpioMsg {
2043 struct SmsMsgHdr_ST xMsgHeader;
2044 u32 msgData[2];
2045 } *pMsg;
2046
2047
2048 if (PinNum > MAX_GPIO_PIN_NUMBER)
2049 return -EINVAL;
2050
2051 totalLen = sizeof(struct SmsMsgHdr_ST) + (2 * sizeof(u32));
2052
2053 buffer = kmalloc(totalLen + SMS_DMA_ALIGNMENT,
2054 GFP_KERNEL | GFP_DMA);
2055 if (!buffer)
2056 return -ENOMEM;
2057
2058 pMsg = (struct SetGpioMsg *) SMS_ALIGN_ADDRESS(buffer);
2059
2060 pMsg->xMsgHeader.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
2061 pMsg->xMsgHeader.msgDstId = HIF_TASK;
2062 pMsg->xMsgHeader.msgFlags = 0;
2063 pMsg->xMsgHeader.msgType = MSG_SMS_GPIO_GET_LEVEL_REQ;
2064 pMsg->xMsgHeader.msgLength = (u16) totalLen;
2065 pMsg->msgData[0] = PinNum;
2066 pMsg->msgData[1] = 0;
2067
2068 /* Send message to SMS */
2069 smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg);
2070 rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
2071 &coredev->gpio_get_level_done);
2072
2073 if (rc != 0) {
2074 if (rc == -ETIME)
2075 sms_err("smscore_gpio_get_level timeout");
2076 else
2077 sms_err("smscore_gpio_get_level error");
2078 }
2079 kfree(buffer);
2080
2081 /* Its a race between other gpio_get_level() and the copy of the single
2082 * global 'coredev->gpio_get_res' to the function's variable 'level'
2083 */
2084 *level = coredev->gpio_get_res;
2085
2086 return rc;
2087}
2088
c5e0bd1a 2089static int __init smscore_module_init(void)
2e5c1ec8 2090{
c6465799 2091 int rc = 0;
2e5c1ec8
MK
2092
2093 INIT_LIST_HEAD(&g_smscore_notifyees);
2094 INIT_LIST_HEAD(&g_smscore_devices);
2095 kmutex_init(&g_smscore_deviceslock);
2096
2097 INIT_LIST_HEAD(&g_smscore_registry);
2098 kmutex_init(&g_smscore_registrylock);
2099
2e5c1ec8
MK
2100 return rc;
2101}
2102
c5e0bd1a 2103static void __exit smscore_module_exit(void)
2e5c1ec8 2104{
2e5c1ec8 2105 kmutex_lock(&g_smscore_deviceslock);
82237416 2106 while (!list_empty(&g_smscore_notifyees)) {
18245e18
MK
2107 struct smscore_device_notifyee_t *notifyee =
2108 (struct smscore_device_notifyee_t *)
2109 g_smscore_notifyees.next;
2e5c1ec8
MK
2110
2111 list_del(&notifyee->entry);
2112 kfree(notifyee);
2113 }
2114 kmutex_unlock(&g_smscore_deviceslock);
2115
2116 kmutex_lock(&g_smscore_registrylock);
82237416 2117 while (!list_empty(&g_smscore_registry)) {
18245e18
MK
2118 struct smscore_registry_entry_t *entry =
2119 (struct smscore_registry_entry_t *)
2120 g_smscore_registry.next;
2e5c1ec8
MK
2121
2122 list_del(&entry->entry);
2123 kfree(entry);
2124 }
2125 kmutex_unlock(&g_smscore_registrylock);
2126
a0c0abcb 2127 sms_debug("");
2e5c1ec8
MK
2128}
2129
2130module_init(smscore_module_init);
2131module_exit(smscore_module_exit);
2132
e0f14c25
US
2133MODULE_DESCRIPTION("Siano MDTV Core module");
2134MODULE_AUTHOR("Siano Mobile Silicon, Inc. (uris@siano-ms.com)");
2e5c1ec8 2135MODULE_LICENSE("GPL");