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