V4L/DVB (11552): Siano: SDIO interface driver - remove two redundant lines
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / media / dvb / siano / smscoreapi.h
CommitLineData
8d4f9d0e 1/*
85447060 2 * Driver for the Siano SMS1xxx USB dongle
8d4f9d0e 3 *
85447060
MK
4 * author: Anatoly Greenblat
5 *
6 * Copyright (c), 2005-2008 Siano Mobile Silicon, Inc.
8d4f9d0e
ST
7 *
8 * This program is free software; you can redistribute it and/or modify
09a29b77 9 * it under the terms of the GNU General Public License version 2 as
85447060 10 * published by the Free Software Foundation;
8d4f9d0e 11 *
85447060
MK
12 * Software distributed under the License is distributed on an "AS IS"
13 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
8d4f9d0e 14 *
85447060 15 * See the GNU General Public License for more details.
8d4f9d0e
ST
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
2e5c1ec8
MK
22#ifndef __smscoreapi_h__
23#define __smscoreapi_h__
24
955e9ca3
ST
25#include <linux/version.h>
26#include <linux/device.h>
27#include <linux/list.h>
28#include <linux/mm.h>
f1f74aa2 29#include <linux/scatterlist.h>
2c6a37bb 30#include <linux/types.h>
955e9ca3 31#include <asm/page.h>
e0f14c25 32#include <linux/mutex.h>
955e9ca3 33
19d703da
ST
34#include "dmxdev.h"
35#include "dvbdev.h"
36#include "dvb_demux.h"
37#include "dvb_frontend.h"
38
955e9ca3 39
955e9ca3
ST
40#define kmutex_init(_p_) mutex_init(_p_)
41#define kmutex_lock(_p_) mutex_lock(_p_)
42#define kmutex_trylock(_p_) mutex_trylock(_p_)
43#define kmutex_unlock(_p_) mutex_unlock(_p_)
44
2e5c1ec8 45#ifndef min
fa830e8a 46#define min(a, b) (((a) < (b)) ? (a) : (b))
2e5c1ec8
MK
47#endif
48
49#define SMS_ALLOC_ALIGNMENT 128
50#define SMS_DMA_ALIGNMENT 16
59bf6b8e 51#define SMS_ALIGN_ADDRESS(addr) \
4411d291 52 ((((uintptr_t)(addr)) + (SMS_DMA_ALIGNMENT-1)) & ~(SMS_DMA_ALIGNMENT-1))
2e5c1ec8
MK
53
54#define SMS_DEVICE_FAMILY2 1
55#define SMS_ROM_NO_RESPONSE 2
56#define SMS_DEVICE_NOT_READY 0x8000000
57
18245e18 58enum sms_device_type_st {
fa830e8a 59 SMS_STELLAR = 0,
f17407a8
MK
60 SMS_NOVA_A0,
61 SMS_NOVA_B0,
62 SMS_VEGA,
63 SMS_NUM_OF_DEVICE_TYPES
18245e18 64};
f17407a8 65
18245e18
MK
66struct smscore_device_t;
67struct smscore_client_t;
68struct smscore_buffer_t;
2e5c1ec8 69
18245e18 70typedef int (*hotplug_t)(struct smscore_device_t *coredev,
59bf6b8e 71 struct device *device, int arrival);
2e5c1ec8
MK
72
73typedef int (*setmode_t)(void *context, int mode);
74typedef void (*detectmode_t)(void *context, int *mode);
75typedef int (*sendrequest_t)(void *context, void *buffer, size_t size);
76typedef int (*loadfirmware_t)(void *context, void *buffer, size_t size);
77typedef int (*preload_t)(void *context);
78typedef int (*postload_t)(void *context);
79
18245e18 80typedef int (*onresponse_t)(void *context, struct smscore_buffer_t *cb);
2e5c1ec8
MK
81typedef void (*onremove_t)(void *context);
82
18245e18 83struct smscore_buffer_t {
82237416 84 /* public members, once passed to clients can be changed freely */
2e5c1ec8
MK
85 struct list_head entry;
86 int size;
87 int offset;
88
82237416 89 /* private members, read-only for clients */
2e5c1ec8
MK
90 void *p;
91 dma_addr_t phys;
92 unsigned long offset_in_common;
18245e18 93};
2e5c1ec8 94
18245e18 95struct smsdevice_params_t {
2e5c1ec8
MK
96 struct device *device;
97
98 int buffer_size;
99 int num_buffers;
100
101 char devpath[32];
102 unsigned long flags;
103
104 setmode_t setmode_handler;
105 detectmode_t detectmode_handler;
106 sendrequest_t sendrequest_handler;
107 preload_t preload_handler;
108 postload_t postload_handler;
109
110 void *context;
18245e18
MK
111 enum sms_device_type_st device_type;
112};
2e5c1ec8 113
18245e18 114struct smsclient_params_t {
2e5c1ec8
MK
115 int initial_id;
116 int data_type;
117 onresponse_t onresponse_handler;
118 onremove_t onremove_handler;
119
120 void *context;
18245e18 121};
2e5c1ec8 122
82237416 123/* GPIO definitions for antenna frequency domain control (SMS8021) */
9e4fb5e7
ST
124#define SMS_ANTENNA_GPIO_0 1
125#define SMS_ANTENNA_GPIO_1 0
126
127#define BW_8_MHZ 0
128#define BW_7_MHZ 1
129#define BW_6_MHZ 2
130#define BW_5_MHZ 3
131#define BW_ISDBT_1SEG 4
132#define BW_ISDBT_3SEG 5
133
134#define MSG_HDR_FLAG_SPLIT_MSG 4
135
136#define MAX_GPIO_PIN_NUMBER 31
137
138#define HIF_TASK 11
139#define SMS_HOST_LIB 150
140#define DVBT_BDA_CONTROL_MSG_ID 201
141
142#define SMS_MAX_PAYLOAD_SIZE 240
143#define SMS_TUNE_TIMEOUT 500
144
145#define MSG_SMS_GPIO_CONFIG_REQ 507
146#define MSG_SMS_GPIO_CONFIG_RES 508
147#define MSG_SMS_GPIO_SET_LEVEL_REQ 509
148#define MSG_SMS_GPIO_SET_LEVEL_RES 510
149#define MSG_SMS_GPIO_GET_LEVEL_REQ 511
150#define MSG_SMS_GPIO_GET_LEVEL_RES 512
151#define MSG_SMS_RF_TUNE_REQ 561
152#define MSG_SMS_RF_TUNE_RES 562
153#define MSG_SMS_INIT_DEVICE_REQ 578
154#define MSG_SMS_INIT_DEVICE_RES 579
155#define MSG_SMS_ADD_PID_FILTER_REQ 601
156#define MSG_SMS_ADD_PID_FILTER_RES 602
157#define MSG_SMS_REMOVE_PID_FILTER_REQ 603
158#define MSG_SMS_REMOVE_PID_FILTER_RES 604
159#define MSG_SMS_DAB_CHANNEL 607
160#define MSG_SMS_GET_PID_FILTER_LIST_REQ 608
161#define MSG_SMS_GET_PID_FILTER_LIST_RES 609
162#define MSG_SMS_GET_STATISTICS_REQ 615
163#define MSG_SMS_GET_STATISTICS_RES 616
164#define MSG_SMS_SET_ANTENNA_CONFIG_REQ 651
165#define MSG_SMS_SET_ANTENNA_CONFIG_RES 652
166#define MSG_SMS_GET_STATISTICS_EX_REQ 653
167#define MSG_SMS_GET_STATISTICS_EX_RES 654
168#define MSG_SMS_SLEEP_RESUME_COMP_IND 655
169#define MSG_SMS_DATA_DOWNLOAD_REQ 660
170#define MSG_SMS_DATA_DOWNLOAD_RES 661
171#define MSG_SMS_SWDOWNLOAD_TRIGGER_REQ 664
172#define MSG_SMS_SWDOWNLOAD_TRIGGER_RES 665
173#define MSG_SMS_SWDOWNLOAD_BACKDOOR_REQ 666
174#define MSG_SMS_SWDOWNLOAD_BACKDOOR_RES 667
175#define MSG_SMS_GET_VERSION_EX_REQ 668
176#define MSG_SMS_GET_VERSION_EX_RES 669
177#define MSG_SMS_SET_CLOCK_OUTPUT_REQ 670
178#define MSG_SMS_I2C_SET_FREQ_REQ 685
179#define MSG_SMS_GENERIC_I2C_REQ 687
180#define MSG_SMS_GENERIC_I2C_RES 688
181#define MSG_SMS_DVBT_BDA_DATA 693
182#define MSG_SW_RELOAD_REQ 697
183#define MSG_SMS_DATA_MSG 699
184#define MSG_SW_RELOAD_START_REQ 702
185#define MSG_SW_RELOAD_START_RES 703
186#define MSG_SW_RELOAD_EXEC_REQ 704
187#define MSG_SW_RELOAD_EXEC_RES 705
188#define MSG_SMS_SPI_INT_LINE_SET_REQ 710
76052bc8
MK
189#define MSG_SMS_GPIO_CONFIG_EX_REQ 712
190#define MSG_SMS_GPIO_CONFIG_EX_RES 713
9e4fb5e7
ST
191#define MSG_SMS_ISDBT_TUNE_REQ 776
192#define MSG_SMS_ISDBT_TUNE_RES 777
193
194#define SMS_INIT_MSG_EX(ptr, type, src, dst, len) do { \
195 (ptr)->msgType = type; (ptr)->msgSrcId = src; (ptr)->msgDstId = dst; \
196 (ptr)->msgLength = len; (ptr)->msgFlags = 0; \
197} while (0)
59bf6b8e
MK
198#define SMS_INIT_MSG(ptr, type, len) \
199 SMS_INIT_MSG_EX(ptr, type, 0, HIF_TASK, len)
9e4fb5e7 200
18245e18 201enum SMS_DEVICE_MODE {
9e4fb5e7
ST
202 DEVICE_MODE_NONE = -1,
203 DEVICE_MODE_DVBT = 0,
204 DEVICE_MODE_DVBH,
205 DEVICE_MODE_DAB_TDMB,
206 DEVICE_MODE_DAB_TDMB_DABIP,
207 DEVICE_MODE_DVBT_BDA,
208 DEVICE_MODE_ISDBT,
209 DEVICE_MODE_ISDBT_BDA,
210 DEVICE_MODE_CMMB,
211 DEVICE_MODE_RAW_TUNER,
212 DEVICE_MODE_MAX,
18245e18 213};
9e4fb5e7 214
18245e18 215struct SmsMsgHdr_ST {
f0333e3d
MK
216 u16 msgType;
217 u8 msgSrcId;
218 u8 msgDstId;
219 u16 msgLength; /* Length of entire message, including header */
220 u16 msgFlags;
18245e18 221};
9e4fb5e7 222
18245e18
MK
223struct SmsMsgData_ST {
224 struct SmsMsgHdr_ST xMsgHeader;
f0333e3d 225 u32 msgData[1];
18245e18 226};
9e4fb5e7 227
18245e18
MK
228struct SmsDataDownload_ST {
229 struct SmsMsgHdr_ST xMsgHeader;
f0333e3d
MK
230 u32 MemAddr;
231 u8 Payload[SMS_MAX_PAYLOAD_SIZE];
18245e18 232};
9e4fb5e7 233
18245e18
MK
234struct SmsVersionRes_ST {
235 struct SmsMsgHdr_ST xMsgHeader;
9e4fb5e7 236
f0333e3d
MK
237 u16 ChipModel; /* e.g. 0x1102 for SMS-1102 "Nova" */
238 u8 Step; /* 0 - Step A */
239 u8 MetalFix; /* 0 - Metal 0 */
9e4fb5e7 240
59bf6b8e
MK
241 u8 FirmwareId; /* 0xFF � ROM, otherwise the
242 * value indicated by
243 * SMSHOSTLIB_DEVICE_MODES_E */
244 u8 SupportedProtocols; /* Bitwise OR combination of
245 * supported protocols */
9e4fb5e7 246
f0333e3d
MK
247 u8 VersionMajor;
248 u8 VersionMinor;
249 u8 VersionPatch;
250 u8 VersionFieldPatch;
9e4fb5e7 251
f0333e3d
MK
252 u8 RomVersionMajor;
253 u8 RomVersionMinor;
254 u8 RomVersionPatch;
255 u8 RomVersionFieldPatch;
9e4fb5e7 256
f0333e3d 257 u8 TextLabel[34];
18245e18 258};
9e4fb5e7 259
18245e18 260struct SmsFirmware_ST {
f0333e3d
MK
261 u32 CheckSum;
262 u32 Length;
263 u32 StartAddress;
264 u8 Payload[1];
18245e18 265};
9e4fb5e7 266
18245e18 267struct SMSHOSTLIB_STATISTICS_ST {
f0333e3d 268 u32 Reserved; /* Reserved */
82237416
MK
269
270 /* Common parameters */
f0333e3d
MK
271 u32 IsRfLocked; /* 0 - not locked, 1 - locked */
272 u32 IsDemodLocked; /* 0 - not locked, 1 - locked */
273 u32 IsExternalLNAOn; /* 0 - external LNA off, 1 - external LNA on */
82237416
MK
274
275 /* Reception quality */
f0333e3d
MK
276 s32 SNR; /* dB */
277 u32 BER; /* Post Viterbi BER [1E-5] */
278 u32 FIB_CRC; /* CRC errors percentage, valid only for DAB */
59bf6b8e
MK
279 u32 TS_PER; /* Transport stream PER, 0xFFFFFFFF indicate N/A,
280 * valid only for DVB-T/H */
281 u32 MFER; /* DVB-H frame error rate in percentage,
282 * 0xFFFFFFFF indicate N/A, valid only for DVB-H */
f0333e3d
MK
283 s32 RSSI; /* dBm */
284 s32 InBandPwr; /* In band power in dBM */
285 s32 CarrierOffset; /* Carrier Offset in bin/1024 */
82237416 286
59bf6b8e 287 /* Transmission parameters, valid only for DVB-T/H */
f0333e3d 288 u32 Frequency; /* Frequency in Hz */
59bf6b8e
MK
289 u32 Bandwidth; /* Bandwidth in MHz */
290 u32 TransmissionMode; /* Transmission Mode, for DAB modes 1-4,
291 * for DVB-T/H FFT mode carriers in Kilos */
292 u32 ModemState; /* from SMS_DvbModemState_ET */
293 u32 GuardInterval; /* Guard Interval, 1 divided by value */
294 u32 CodeRate; /* Code Rate from SMS_DvbModemState_ET */
295 u32 LPCodeRate; /* Low Priority Code Rate from SMS_DvbModemState_ET */
296 u32 Hierarchy; /* Hierarchy from SMS_Hierarchy_ET */
297 u32 Constellation; /* Constellation from SMS_Constellation_ET */
82237416
MK
298
299 /* Burst parameters, valid only for DVB-H */
59bf6b8e
MK
300 u32 BurstSize; /* Current burst size in bytes */
301 u32 BurstDuration; /* Current burst duration in mSec */
302 u32 BurstCycleTime; /* Current burst cycle time in mSec */
303 u32 CalculatedBurstCycleTime; /* Current burst cycle time in mSec,
304 * as calculated by demodulator */
305 u32 NumOfRows; /* Number of rows in MPE table */
306 u32 NumOfPaddCols; /* Number of padding columns in MPE table */
307 u32 NumOfPunctCols; /* Number of puncturing columns in MPE table */
308 /* Burst parameters */
f0333e3d
MK
309 u32 ErrorTSPackets; /* Number of erroneous transport-stream packets */
310 u32 TotalTSPackets; /* Total number of transport-stream packets */
59bf6b8e
MK
311 u32 NumOfValidMpeTlbs; /* Number of MPE tables which do not include
312 * errors after MPE RS decoding */
313 u32 NumOfInvalidMpeTlbs; /* Number of MPE tables which include errors
314 * after MPE RS decoding */
315 u32 NumOfCorrectedMpeTlbs; /* Number of MPE tables which were corrected
316 * by MPE RS decoding */
82237416
MK
317
318 /* Common params */
f0333e3d
MK
319 u32 BERErrorCount; /* Number of errornous SYNC bits. */
320 u32 BERBitCount; /* Total number of SYNC bits. */
82237416
MK
321
322 /* Interface information */
f0333e3d 323 u32 SmsToHostTxErrors; /* Total number of transmission errors. */
82237416
MK
324
325 /* DAB/T-DMB */
f0333e3d 326 u32 PreBER; /* DAB/T-DMB only: Pre Viterbi BER [1E-5] */
82237416
MK
327
328 /* DVB-H TPS parameters */
59bf6b8e
MK
329 u32 CellId; /* TPS Cell ID in bits 15..0, bits 31..16 zero;
330 * if set to 0xFFFFFFFF cell_id not yet recovered */
9e4fb5e7 331
18245e18 332};
9e4fb5e7 333
18245e18 334struct SmsMsgStatisticsInfo_ST {
f0333e3d 335 u32 RequestResult;
9e4fb5e7 336
18245e18 337 struct SMSHOSTLIB_STATISTICS_ST Stat;
9e4fb5e7 338
82237416 339 /* Split the calc of the SNR in DAB */
f0333e3d
MK
340 u32 Signal; /* dB */
341 u32 Noise; /* dB */
9e4fb5e7 342
18245e18 343};
82237416 344
9e4fb5e7 345
76052bc8
MK
346struct smscore_gpio_config {
347#define SMS_GPIO_DIRECTION_INPUT 0
348#define SMS_GPIO_DIRECTION_OUTPUT 1
349 u8 direction;
350
351#define SMS_GPIO_PULLUPDOWN_NONE 0
352#define SMS_GPIO_PULLUPDOWN_PULLDOWN 1
353#define SMS_GPIO_PULLUPDOWN_PULLUP 2
354#define SMS_GPIO_PULLUPDOWN_KEEPER 3
355 u8 pullupdown;
356
357#define SMS_GPIO_INPUTCHARACTERISTICS_NORMAL 0
358#define SMS_GPIO_INPUTCHARACTERISTICS_SCHMITT 1
359 u8 inputcharacteristics;
360
361#define SMS_GPIO_OUTPUTSLEWRATE_FAST 0
362#define SMS_GPIO_OUTPUTSLEWRATE_SLOW 1
363 u8 outputslewrate;
364
365#define SMS_GPIO_OUTPUTDRIVING_4mA 0
366#define SMS_GPIO_OUTPUTDRIVING_8mA 1
367#define SMS_GPIO_OUTPUTDRIVING_12mA 2
368#define SMS_GPIO_OUTPUTDRIVING_16mA 3
369 u8 outputdriving;
370};
371
2e5c1ec8
MK
372extern void smscore_registry_setmode(char *devpath, int mode);
373extern int smscore_registry_getmode(char *devpath);
374
375extern int smscore_register_hotplug(hotplug_t hotplug);
376extern void smscore_unregister_hotplug(hotplug_t hotplug);
377
18245e18
MK
378extern int smscore_register_device(struct smsdevice_params_t *params,
379 struct smscore_device_t **coredev);
380extern void smscore_unregister_device(struct smscore_device_t *coredev);
2e5c1ec8 381
18245e18
MK
382extern int smscore_start_device(struct smscore_device_t *coredev);
383extern int smscore_load_firmware(struct smscore_device_t *coredev,
384 char *filename,
385 loadfirmware_t loadfirmware_handler);
2e5c1ec8 386
18245e18
MK
387extern int smscore_set_device_mode(struct smscore_device_t *coredev, int mode);
388extern int smscore_get_device_mode(struct smscore_device_t *coredev);
2e5c1ec8 389
18245e18
MK
390extern int smscore_register_client(struct smscore_device_t *coredev,
391 struct smsclient_params_t *params,
392 struct smscore_client_t **client);
393extern void smscore_unregister_client(struct smscore_client_t *client);
2e5c1ec8 394
18245e18 395extern int smsclient_sendrequest(struct smscore_client_t *client,
82237416 396 void *buffer, size_t size);
18245e18
MK
397extern void smscore_onresponse(struct smscore_device_t *coredev,
398 struct smscore_buffer_t *cb);
2e5c1ec8 399
e0f14c25
US
400extern int smscore_get_common_buffer_size(struct smscore_device_t *coredev);
401extern int smscore_map_common_buffer(struct smscore_device_t *coredev,
402 struct vm_area_struct *vma);
b9391f41
MK
403extern int smscore_get_fw_filename(struct smscore_device_t *coredev,
404 int mode, char *filename);
405extern int smscore_send_fw_file(struct smscore_device_t *coredev,
406 u8 *ufwbuf, int size);
2e5c1ec8 407
b1d8f9f5
MK
408extern
409struct smscore_buffer_t *smscore_getbuffer(struct smscore_device_t *coredev);
18245e18
MK
410extern void smscore_putbuffer(struct smscore_device_t *coredev,
411 struct smscore_buffer_t *cb);
2e5c1ec8 412
76052bc8
MK
413int smscore_configure_gpio(struct smscore_device_t *coredev, u32 pin,
414 struct smscore_gpio_config *pinconfig);
415int smscore_set_gpio(struct smscore_device_t *coredev, u32 pin, int level);
416
1c11d546
MK
417void smscore_set_board_id(struct smscore_device_t *core, int id);
418int smscore_get_board_id(struct smscore_device_t *core);
419
7b29e10d
MK
420int smscore_led_state(struct smscore_device_t *core, int led);
421
3dd24378 422
f14d56a9
MK
423/* ------------------------------------------------------------------------ */
424
f14d56a9
MK
425#define DBG_INFO 1
426#define DBG_ADV 2
427
428#define sms_printk(kern, fmt, arg...) \
429 printk(kern "%s: " fmt "\n", __func__, ##arg)
430
431#define dprintk(kern, lvl, fmt, arg...) do {\
b9391f41 432 if (sms_dbg & lvl) \
f14d56a9
MK
433 sms_printk(kern, fmt, ##arg); } while (0)
434
5068b7a4 435#define sms_log(fmt, arg...) sms_printk(KERN_INFO, fmt, ##arg)
a0c0abcb 436#define sms_err(fmt, arg...) \
c65c7a65 437 sms_printk(KERN_ERR, "line: %d: " fmt, __LINE__, ##arg)
5068b7a4 438#define sms_warn(fmt, arg...) sms_printk(KERN_WARNING, fmt, ##arg)
a0c0abcb 439#define sms_info(fmt, arg...) \
f14d56a9 440 dprintk(KERN_INFO, DBG_INFO, fmt, ##arg)
a0c0abcb 441#define sms_debug(fmt, arg...) \
f14d56a9 442 dprintk(KERN_DEBUG, DBG_ADV, fmt, ##arg)
068d6c0f
MK
443
444
82237416 445#endif /* __smscoreapi_h__ */