Merge branch 'core-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6] / drivers / media / dvb / siano / smscoreapi.h
1 /****************************************************************
2
3 Siano Mobile Silicon, Inc.
4 MDTV receiver kernel modules.
5 Copyright (C) 2006-2008, Uri Shkolnik, Anatoly Greenblat
6
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 2 of the License, or
10 (at your option) any later version.
11
12  This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20 ****************************************************************/
21
22 #ifndef __SMS_CORE_API_H__
23 #define __SMS_CORE_API_H__
24
25 #include <linux/version.h>
26 #include <linux/device.h>
27 #include <linux/list.h>
28 #include <linux/mm.h>
29 #include <linux/scatterlist.h>
30 #include <linux/types.h>
31 #include <linux/mutex.h>
32 #include <linux/wait.h>
33 #include <linux/timer.h>
34
35 #include <asm/page.h>
36
37 #include "smsir.h"
38
39 #define kmutex_init(_p_) mutex_init(_p_)
40 #define kmutex_lock(_p_) mutex_lock(_p_)
41 #define kmutex_trylock(_p_) mutex_trylock(_p_)
42 #define kmutex_unlock(_p_) mutex_unlock(_p_)
43
44 #ifndef min
45 #define min(a, b) (((a) < (b)) ? (a) : (b))
46 #endif
47
48 #define SMS_PROTOCOL_MAX_RAOUNDTRIP_MS                  (10000)
49 #define SMS_ALLOC_ALIGNMENT                             128
50 #define SMS_DMA_ALIGNMENT                               16
51 #define SMS_ALIGN_ADDRESS(addr) \
52         ((((uintptr_t)(addr)) + (SMS_DMA_ALIGNMENT-1)) & ~(SMS_DMA_ALIGNMENT-1))
53
54 #define SMS_DEVICE_FAMILY2                              1
55 #define SMS_ROM_NO_RESPONSE                             2
56 #define SMS_DEVICE_NOT_READY                            0x8000000
57
58 enum sms_device_type_st {
59         SMS_STELLAR = 0,
60         SMS_NOVA_A0,
61         SMS_NOVA_B0,
62         SMS_VEGA,
63         SMS_NUM_OF_DEVICE_TYPES
64 };
65
66 struct smscore_device_t;
67 struct smscore_client_t;
68 struct smscore_buffer_t;
69
70 typedef int (*hotplug_t)(struct smscore_device_t *coredev,
71                          struct device *device, int arrival);
72
73 typedef int (*setmode_t)(void *context, int mode);
74 typedef void (*detectmode_t)(void *context, int *mode);
75 typedef int (*sendrequest_t)(void *context, void *buffer, size_t size);
76 typedef int (*loadfirmware_t)(void *context, void *buffer, size_t size);
77 typedef int (*preload_t)(void *context);
78 typedef int (*postload_t)(void *context);
79
80 typedef int (*onresponse_t)(void *context, struct smscore_buffer_t *cb);
81 typedef void (*onremove_t)(void *context);
82
83 struct smscore_buffer_t {
84         /* public members, once passed to clients can be changed freely */
85         struct list_head entry;
86         int size;
87         int offset;
88
89         /* private members, read-only for clients */
90         void *p;
91         dma_addr_t phys;
92         unsigned long offset_in_common;
93 };
94
95 struct smsdevice_params_t {
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;
111         enum sms_device_type_st device_type;
112 };
113
114 struct smsclient_params_t {
115         int                             initial_id;
116         int                             data_type;
117         onresponse_t    onresponse_handler;
118         onremove_t              onremove_handler;
119         void                    *context;
120 };
121
122 struct smscore_device_t {
123         struct list_head entry;
124
125         struct list_head clients;
126         struct list_head subclients;
127         spinlock_t clientslock;
128
129         struct list_head buffers;
130         spinlock_t bufferslock;
131         int num_buffers;
132
133         void *common_buffer;
134         int common_buffer_size;
135         dma_addr_t common_buffer_phys;
136
137         void *context;
138         struct device *device;
139
140         char devpath[32];
141         unsigned long device_flags;
142
143         setmode_t setmode_handler;
144         detectmode_t detectmode_handler;
145         sendrequest_t sendrequest_handler;
146         preload_t preload_handler;
147         postload_t postload_handler;
148
149         int mode, modes_supported;
150
151         /* host <--> device messages */
152         struct completion version_ex_done, data_download_done, trigger_done;
153         struct completion init_device_done, reload_start_done, resume_done;
154         struct completion gpio_configuration_done, gpio_set_level_done;
155         struct completion gpio_get_level_done, ir_init_done;
156
157         /* Buffer management */
158         wait_queue_head_t buffer_mng_waitq;
159
160         /* GPIO */
161         int gpio_get_res;
162
163         /* Target hardware board */
164         int board_id;
165
166         /* Firmware */
167         u8 *fw_buf;
168         u32 fw_buf_size;
169
170         /* Infrared (IR) */
171         struct ir_t ir;
172
173         int led_state;
174 };
175
176 /* GPIO definitions for antenna frequency domain control (SMS8021) */
177 #define SMS_ANTENNA_GPIO_0                                      1
178 #define SMS_ANTENNA_GPIO_1                                      0
179
180 #define BW_8_MHZ                                                        0
181 #define BW_7_MHZ                                                        1
182 #define BW_6_MHZ                                                        2
183 #define BW_5_MHZ                                                        3
184 #define BW_ISDBT_1SEG                                           4
185 #define BW_ISDBT_3SEG                                           5
186
187 #define MSG_HDR_FLAG_SPLIT_MSG                          4
188
189 #define MAX_GPIO_PIN_NUMBER                                     31
190
191 #define HIF_TASK                                                        11
192 #define SMS_HOST_LIB                                            150
193 #define DVBT_BDA_CONTROL_MSG_ID                         201
194
195 #define SMS_MAX_PAYLOAD_SIZE                            240
196 #define SMS_TUNE_TIMEOUT                                        500
197
198 #define MSG_SMS_GPIO_CONFIG_REQ                         507
199 #define MSG_SMS_GPIO_CONFIG_RES                         508
200 #define MSG_SMS_GPIO_SET_LEVEL_REQ                      509
201 #define MSG_SMS_GPIO_SET_LEVEL_RES                      510
202 #define MSG_SMS_GPIO_GET_LEVEL_REQ                      511
203 #define MSG_SMS_GPIO_GET_LEVEL_RES                      512
204 #define MSG_SMS_RF_TUNE_REQ                                     561
205 #define MSG_SMS_RF_TUNE_RES                                     562
206 #define MSG_SMS_INIT_DEVICE_REQ                         578
207 #define MSG_SMS_INIT_DEVICE_RES                         579
208 #define MSG_SMS_ADD_PID_FILTER_REQ                      601
209 #define MSG_SMS_ADD_PID_FILTER_RES                      602
210 #define MSG_SMS_REMOVE_PID_FILTER_REQ                   603
211 #define MSG_SMS_REMOVE_PID_FILTER_RES                   604
212 #define MSG_SMS_DAB_CHANNEL                             607
213 #define MSG_SMS_GET_PID_FILTER_LIST_REQ                 608
214 #define MSG_SMS_GET_PID_FILTER_LIST_RES                 609
215 #define MSG_SMS_HO_PER_SLICES_IND                       630
216 #define MSG_SMS_SET_ANTENNA_CONFIG_REQ                  651
217 #define MSG_SMS_SET_ANTENNA_CONFIG_RES                  652
218 #define MSG_SMS_SLEEP_RESUME_COMP_IND                   655
219 #define MSG_SMS_DATA_DOWNLOAD_REQ                       660
220 #define MSG_SMS_DATA_DOWNLOAD_RES                       661
221 #define MSG_SMS_SWDOWNLOAD_TRIGGER_REQ          664
222 #define MSG_SMS_SWDOWNLOAD_TRIGGER_RES          665
223 #define MSG_SMS_SWDOWNLOAD_BACKDOOR_REQ         666
224 #define MSG_SMS_SWDOWNLOAD_BACKDOOR_RES         667
225 #define MSG_SMS_GET_VERSION_EX_REQ                      668
226 #define MSG_SMS_GET_VERSION_EX_RES                      669
227 #define MSG_SMS_SET_CLOCK_OUTPUT_REQ            670
228 #define MSG_SMS_I2C_SET_FREQ_REQ                        685
229 #define MSG_SMS_GENERIC_I2C_REQ                         687
230 #define MSG_SMS_GENERIC_I2C_RES                         688
231 #define MSG_SMS_DVBT_BDA_DATA                           693
232 #define MSG_SW_RELOAD_REQ                                       697
233 #define MSG_SMS_DATA_MSG                                        699
234 #define MSG_SW_RELOAD_START_REQ                         702
235 #define MSG_SW_RELOAD_START_RES                         703
236 #define MSG_SW_RELOAD_EXEC_REQ                          704
237 #define MSG_SW_RELOAD_EXEC_RES                          705
238 #define MSG_SMS_SPI_INT_LINE_SET_REQ            710
239 #define MSG_SMS_GPIO_CONFIG_EX_REQ                      712
240 #define MSG_SMS_GPIO_CONFIG_EX_RES                      713
241 #define MSG_SMS_ISDBT_TUNE_REQ                          776
242 #define MSG_SMS_ISDBT_TUNE_RES                          777
243 #define MSG_SMS_TRANSMISSION_IND                        782
244 #define MSG_SMS_START_IR_REQ                            800
245 #define MSG_SMS_START_IR_RES                            801
246 #define MSG_SMS_IR_SAMPLES_IND                          802
247 #define MSG_SMS_SIGNAL_DETECTED_IND                     827
248 #define MSG_SMS_NO_SIGNAL_IND                           828
249
250 #define SMS_INIT_MSG_EX(ptr, type, src, dst, len) do { \
251         (ptr)->msgType = type; (ptr)->msgSrcId = src; (ptr)->msgDstId = dst; \
252         (ptr)->msgLength = len; (ptr)->msgFlags = 0; \
253 } while (0)
254
255 #define SMS_INIT_MSG(ptr, type, len) \
256         SMS_INIT_MSG_EX(ptr, type, 0, HIF_TASK, len)
257
258 enum SMS_DVB3_EVENTS {
259         DVB3_EVENT_INIT = 0,
260         DVB3_EVENT_SLEEP,
261         DVB3_EVENT_HOTPLUG,
262         DVB3_EVENT_FE_LOCK,
263         DVB3_EVENT_FE_UNLOCK,
264         DVB3_EVENT_UNC_OK,
265         DVB3_EVENT_UNC_ERR
266 };
267
268 enum SMS_DEVICE_MODE {
269         DEVICE_MODE_NONE = -1,
270         DEVICE_MODE_DVBT = 0,
271         DEVICE_MODE_DVBH,
272         DEVICE_MODE_DAB_TDMB,
273         DEVICE_MODE_DAB_TDMB_DABIP,
274         DEVICE_MODE_DVBT_BDA,
275         DEVICE_MODE_ISDBT,
276         DEVICE_MODE_ISDBT_BDA,
277         DEVICE_MODE_CMMB,
278         DEVICE_MODE_RAW_TUNER,
279         DEVICE_MODE_MAX,
280 };
281
282 struct SmsMsgHdr_ST {
283         u16     msgType;
284         u8      msgSrcId;
285         u8      msgDstId;
286         u16     msgLength; /* Length of entire message, including header */
287         u16     msgFlags;
288 };
289
290 struct SmsMsgData_ST {
291         struct SmsMsgHdr_ST xMsgHeader;
292         u32 msgData[1];
293 };
294
295 struct SmsMsgData_ST2 {
296         struct SmsMsgHdr_ST xMsgHeader;
297         u32 msgData[2];
298 };
299
300 struct SmsDataDownload_ST {
301         struct SmsMsgHdr_ST     xMsgHeader;
302         u32                     MemAddr;
303         u8                      Payload[SMS_MAX_PAYLOAD_SIZE];
304 };
305
306 struct SmsVersionRes_ST {
307         struct SmsMsgHdr_ST     xMsgHeader;
308
309         u16             ChipModel; /* e.g. 0x1102 for SMS-1102 "Nova" */
310         u8              Step; /* 0 - Step A */
311         u8              MetalFix; /* 0 - Metal 0 */
312
313         /* FirmwareId 0xFF if ROM, otherwise the
314          * value indicated by SMSHOSTLIB_DEVICE_MODES_E */
315         u8 FirmwareId;
316         /* SupportedProtocols Bitwise OR combination of
317                                              * supported protocols */
318         u8 SupportedProtocols;
319
320         u8              VersionMajor;
321         u8              VersionMinor;
322         u8              VersionPatch;
323         u8              VersionFieldPatch;
324
325         u8              RomVersionMajor;
326         u8              RomVersionMinor;
327         u8              RomVersionPatch;
328         u8              RomVersionFieldPatch;
329
330         u8              TextLabel[34];
331 };
332
333 struct SmsFirmware_ST {
334         u32                     CheckSum;
335         u32                     Length;
336         u32                     StartAddress;
337         u8                      Payload[1];
338 };
339
340 /* Statistics information returned as response for
341  * SmsHostApiGetStatistics_Req */
342 struct SMSHOSTLIB_STATISTICS_S {
343         u32 Reserved;           /* Reserved */
344
345         /* Common parameters */
346         u32 IsRfLocked;         /* 0 - not locked, 1 - locked */
347         u32 IsDemodLocked;      /* 0 - not locked, 1 - locked */
348         u32 IsExternalLNAOn;    /* 0 - external LNA off, 1 - external LNA on */
349
350         /* Reception quality */
351         s32 SNR;                /* dB */
352         u32 BER;                /* Post Viterbi BER [1E-5] */
353         u32 FIB_CRC;            /* CRC errors percentage, valid only for DAB */
354         u32 TS_PER;             /* Transport stream PER,
355         0xFFFFFFFF indicate N/A, valid only for DVB-T/H */
356         u32 MFER;               /* DVB-H frame error rate in percentage,
357         0xFFFFFFFF indicate N/A, valid only for DVB-H */
358         s32 RSSI;               /* dBm */
359         s32 InBandPwr;          /* In band power in dBM */
360         s32 CarrierOffset;      /* Carrier Offset in bin/1024 */
361
362         /* Transmission parameters */
363         u32 Frequency;          /* Frequency in Hz */
364         u32 Bandwidth;          /* Bandwidth in MHz, valid only for DVB-T/H */
365         u32 TransmissionMode;   /* Transmission Mode, for DAB modes 1-4,
366         for DVB-T/H FFT mode carriers in Kilos */
367         u32 ModemState;         /* from SMSHOSTLIB_DVB_MODEM_STATE_ET,
368         valid only for DVB-T/H */
369         u32 GuardInterval;      /* Guard Interval from
370         SMSHOSTLIB_GUARD_INTERVALS_ET,  valid only for DVB-T/H */
371         u32 CodeRate;           /* Code Rate from SMSHOSTLIB_CODE_RATE_ET,
372         valid only for DVB-T/H */
373         u32 LPCodeRate;         /* Low Priority Code Rate from
374         SMSHOSTLIB_CODE_RATE_ET, valid only for DVB-T/H */
375         u32 Hierarchy;          /* Hierarchy from SMSHOSTLIB_HIERARCHY_ET,
376         valid only for DVB-T/H */
377         u32 Constellation;      /* Constellation from
378         SMSHOSTLIB_CONSTELLATION_ET, valid only for DVB-T/H */
379
380         /* Burst parameters, valid only for DVB-H */
381         u32 BurstSize;          /* Current burst size in bytes,
382         valid only for DVB-H */
383         u32 BurstDuration;      /* Current burst duration in mSec,
384         valid only for DVB-H */
385         u32 BurstCycleTime;     /* Current burst cycle time in mSec,
386         valid only for DVB-H */
387         u32 CalculatedBurstCycleTime;/* Current burst cycle time in mSec,
388         as calculated by demodulator, valid only for DVB-H */
389         u32 NumOfRows;          /* Number of rows in MPE table,
390         valid only for DVB-H */
391         u32 NumOfPaddCols;      /* Number of padding columns in MPE table,
392         valid only for DVB-H */
393         u32 NumOfPunctCols;     /* Number of puncturing columns in MPE table,
394         valid only for DVB-H */
395         u32 ErrorTSPackets;     /* Number of erroneous
396         transport-stream packets */
397         u32 TotalTSPackets;     /* Total number of transport-stream packets */
398         u32 NumOfValidMpeTlbs;  /* Number of MPE tables which do not include
399         errors after MPE RS decoding */
400         u32 NumOfInvalidMpeTlbs;/* Number of MPE tables which include errors
401         after MPE RS decoding */
402         u32 NumOfCorrectedMpeTlbs;/* Number of MPE tables which were
403         corrected by MPE RS decoding */
404         /* Common params */
405         u32 BERErrorCount;      /* Number of errornous SYNC bits. */
406         u32 BERBitCount;        /* Total number of SYNC bits. */
407
408         /* Interface information */
409         u32 SmsToHostTxErrors;  /* Total number of transmission errors. */
410
411         /* DAB/T-DMB */
412         u32 PreBER;             /* DAB/T-DMB only: Pre Viterbi BER [1E-5] */
413
414         /* DVB-H TPS parameters */
415         u32 CellId;             /* TPS Cell ID in bits 15..0, bits 31..16 zero;
416          if set to 0xFFFFFFFF cell_id not yet recovered */
417         u32 DvbhSrvIndHP;       /* DVB-H service indication info, bit 1 -
418         Time Slicing indicator, bit 0 - MPE-FEC indicator */
419         u32 DvbhSrvIndLP;       /* DVB-H service indication info, bit 1 -
420         Time Slicing indicator, bit 0 - MPE-FEC indicator */
421
422         u32 NumMPEReceived;     /* DVB-H, Num MPE section received */
423
424         u32 ReservedFields[10]; /* Reserved */
425 };
426
427 struct PID_STATISTICS_DATA_S {
428         struct PID_BURST_S {
429                 u32 size;
430                 u32 padding_cols;
431                 u32 punct_cols;
432                 u32 duration;
433                 u32 cycle;
434                 u32 calc_cycle;
435         } burst;
436
437         u32 tot_tbl_cnt;
438         u32 invalid_tbl_cnt;
439         u32 tot_cor_tbl;
440 };
441
442 struct PID_DATA_S {
443         u32 pid;
444         u32 num_rows;
445         struct PID_STATISTICS_DATA_S pid_statistics;
446 };
447
448 #define CORRECT_STAT_RSSI(_stat) ((_stat).RSSI *= -1)
449 #define CORRECT_STAT_BANDWIDTH(_stat) (_stat.Bandwidth = 8 - _stat.Bandwidth)
450 #define CORRECT_STAT_TRANSMISSON_MODE(_stat) \
451         if (_stat.TransmissionMode == 0) \
452                 _stat.TransmissionMode = 2; \
453         else if (_stat.TransmissionMode == 1) \
454                 _stat.TransmissionMode = 8; \
455                 else \
456                         _stat.TransmissionMode = 4;
457
458 struct TRANSMISSION_STATISTICS_S {
459         u32 Frequency;          /* Frequency in Hz */
460         u32 Bandwidth;          /* Bandwidth in MHz */
461         u32 TransmissionMode;   /* FFT mode carriers in Kilos */
462         u32 GuardInterval;      /* Guard Interval from
463         SMSHOSTLIB_GUARD_INTERVALS_ET */
464         u32 CodeRate;           /* Code Rate from SMSHOSTLIB_CODE_RATE_ET */
465         u32 LPCodeRate;         /* Low Priority Code Rate from
466         SMSHOSTLIB_CODE_RATE_ET */
467         u32 Hierarchy;          /* Hierarchy from SMSHOSTLIB_HIERARCHY_ET */
468         u32 Constellation;      /* Constellation from
469         SMSHOSTLIB_CONSTELLATION_ET */
470
471         /* DVB-H TPS parameters */
472         u32 CellId;             /* TPS Cell ID in bits 15..0, bits 31..16 zero;
473          if set to 0xFFFFFFFF cell_id not yet recovered */
474         u32 DvbhSrvIndHP;       /* DVB-H service indication info, bit 1 -
475          Time Slicing indicator, bit 0 - MPE-FEC indicator */
476         u32 DvbhSrvIndLP;       /* DVB-H service indication info, bit 1 -
477          Time Slicing indicator, bit 0 - MPE-FEC indicator */
478         u32 IsDemodLocked;      /* 0 - not locked, 1 - locked */
479 };
480
481 struct RECEPTION_STATISTICS_S {
482         u32 IsRfLocked;         /* 0 - not locked, 1 - locked */
483         u32 IsDemodLocked;      /* 0 - not locked, 1 - locked */
484         u32 IsExternalLNAOn;    /* 0 - external LNA off, 1 - external LNA on */
485
486         u32 ModemState;         /* from SMSHOSTLIB_DVB_MODEM_STATE_ET */
487         s32 SNR;                /* dB */
488         u32 BER;                /* Post Viterbi BER [1E-5] */
489         u32 BERErrorCount;      /* Number of erronous SYNC bits. */
490         u32 BERBitCount;        /* Total number of SYNC bits. */
491         u32 TS_PER;             /* Transport stream PER,
492         0xFFFFFFFF indicate N/A */
493         u32 MFER;               /* DVB-H frame error rate in percentage,
494         0xFFFFFFFF indicate N/A, valid only for DVB-H */
495         s32 RSSI;               /* dBm */
496         s32 InBandPwr;          /* In band power in dBM */
497         s32 CarrierOffset;      /* Carrier Offset in bin/1024 */
498         u32 ErrorTSPackets;     /* Number of erroneous
499         transport-stream packets */
500         u32 TotalTSPackets;     /* Total number of transport-stream packets */
501
502         s32 MRC_SNR;            /* dB */
503         s32 MRC_RSSI;           /* dBm */
504         s32 MRC_InBandPwr;      /* In band power in dBM */
505 };
506
507
508 /* Statistics information returned as response for
509  * SmsHostApiGetStatisticsEx_Req for DVB applications, SMS1100 and up */
510 struct SMSHOSTLIB_STATISTICS_DVB_S {
511         /* Reception */
512         struct RECEPTION_STATISTICS_S ReceptionData;
513
514         /* Transmission parameters */
515         struct TRANSMISSION_STATISTICS_S TransmissionData;
516
517         /* Burst parameters, valid only for DVB-H */
518 #define SRVM_MAX_PID_FILTERS 8
519         struct PID_DATA_S PidData[SRVM_MAX_PID_FILTERS];
520 };
521
522 struct SRVM_SIGNAL_STATUS_S {
523         u32 result;
524         u32 snr;
525         u32 tsPackets;
526         u32 etsPackets;
527         u32 constellation;
528         u32 hpCode;
529         u32 tpsSrvIndLP;
530         u32 tpsSrvIndHP;
531         u32 cellId;
532         u32 reason;
533
534         s32 inBandPower;
535         u32 requestId;
536 };
537
538 struct SMSHOSTLIB_I2C_REQ_ST {
539         u32     DeviceAddress; /* I2c device address */
540         u32     WriteCount; /* number of bytes to write */
541         u32     ReadCount; /* number of bytes to read */
542         u8      Data[1];
543 };
544
545 struct SMSHOSTLIB_I2C_RES_ST {
546         u32     Status; /* non-zero value in case of failure */
547         u32     ReadCount; /* number of bytes read */
548         u8      Data[1];
549 };
550
551
552 struct smscore_config_gpio {
553 #define SMS_GPIO_DIRECTION_INPUT  0
554 #define SMS_GPIO_DIRECTION_OUTPUT 1
555         u8 direction;
556
557 #define SMS_GPIO_PULLUPDOWN_NONE     0
558 #define SMS_GPIO_PULLUPDOWN_PULLDOWN 1
559 #define SMS_GPIO_PULLUPDOWN_PULLUP   2
560 #define SMS_GPIO_PULLUPDOWN_KEEPER   3
561         u8 pullupdown;
562
563 #define SMS_GPIO_INPUTCHARACTERISTICS_NORMAL  0
564 #define SMS_GPIO_INPUTCHARACTERISTICS_SCHMITT 1
565         u8 inputcharacteristics;
566
567 #define SMS_GPIO_OUTPUTSLEWRATE_FAST 0
568 #define SMS_GPIO_OUTPUTSLEWRATE_SLOW 1
569         u8 outputslewrate;
570
571 #define SMS_GPIO_OUTPUTDRIVING_4mA  0
572 #define SMS_GPIO_OUTPUTDRIVING_8mA  1
573 #define SMS_GPIO_OUTPUTDRIVING_12mA 2
574 #define SMS_GPIO_OUTPUTDRIVING_16mA 3
575         u8 outputdriving;
576 };
577
578 struct smscore_gpio_config {
579 #define SMS_GPIO_DIRECTION_INPUT  0
580 #define SMS_GPIO_DIRECTION_OUTPUT 1
581         u8 Direction;
582
583 #define SMS_GPIO_PULL_UP_DOWN_NONE     0
584 #define SMS_GPIO_PULL_UP_DOWN_PULLDOWN 1
585 #define SMS_GPIO_PULL_UP_DOWN_PULLUP   2
586 #define SMS_GPIO_PULL_UP_DOWN_KEEPER   3
587         u8 PullUpDown;
588
589 #define SMS_GPIO_INPUT_CHARACTERISTICS_NORMAL  0
590 #define SMS_GPIO_INPUT_CHARACTERISTICS_SCHMITT 1
591         u8 InputCharacteristics;
592
593 #define SMS_GPIO_OUTPUT_SLEW_RATE_SLOW          1 /* 10xx */
594 #define SMS_GPIO_OUTPUT_SLEW_RATE_FAST          0 /* 10xx */
595
596
597 #define SMS_GPIO_OUTPUT_SLEW_RATE_0_45_V_NS     0 /* 11xx */
598 #define SMS_GPIO_OUTPUT_SLEW_RATE_0_9_V_NS      1 /* 11xx */
599 #define SMS_GPIO_OUTPUT_SLEW_RATE_1_7_V_NS      2 /* 11xx */
600 #define SMS_GPIO_OUTPUT_SLEW_RATE_3_3_V_NS      3 /* 11xx */
601         u8 OutputSlewRate;
602
603 #define SMS_GPIO_OUTPUT_DRIVING_S_4mA           0 /* 10xx */
604 #define SMS_GPIO_OUTPUT_DRIVING_S_8mA           1 /* 10xx */
605 #define SMS_GPIO_OUTPUT_DRIVING_S_12mA          2 /* 10xx */
606 #define SMS_GPIO_OUTPUT_DRIVING_S_16mA          3 /* 10xx */
607
608 #define SMS_GPIO_OUTPUT_DRIVING_1_5mA           0 /* 11xx */
609 #define SMS_GPIO_OUTPUT_DRIVING_2_8mA           1 /* 11xx */
610 #define SMS_GPIO_OUTPUT_DRIVING_4mA             2 /* 11xx */
611 #define SMS_GPIO_OUTPUT_DRIVING_7mA             3 /* 11xx */
612 #define SMS_GPIO_OUTPUT_DRIVING_10mA            4 /* 11xx */
613 #define SMS_GPIO_OUTPUT_DRIVING_11mA            5 /* 11xx */
614 #define SMS_GPIO_OUTPUT_DRIVING_14mA            6 /* 11xx */
615 #define SMS_GPIO_OUTPUT_DRIVING_16mA            7 /* 11xx */
616         u8 OutputDriving;
617 };
618
619 extern void smscore_registry_setmode(char *devpath, int mode);
620 extern int smscore_registry_getmode(char *devpath);
621
622 extern int smscore_register_hotplug(hotplug_t hotplug);
623 extern void smscore_unregister_hotplug(hotplug_t hotplug);
624
625 extern int smscore_register_device(struct smsdevice_params_t *params,
626                                    struct smscore_device_t **coredev);
627 extern void smscore_unregister_device(struct smscore_device_t *coredev);
628
629 extern int smscore_start_device(struct smscore_device_t *coredev);
630 extern int smscore_load_firmware(struct smscore_device_t *coredev,
631                                  char *filename,
632                                  loadfirmware_t loadfirmware_handler);
633
634 extern int smscore_set_device_mode(struct smscore_device_t *coredev, int mode);
635 extern int smscore_get_device_mode(struct smscore_device_t *coredev);
636
637 extern int smscore_register_client(struct smscore_device_t *coredev,
638                                     struct smsclient_params_t *params,
639                                     struct smscore_client_t **client);
640 extern void smscore_unregister_client(struct smscore_client_t *client);
641
642 extern int smsclient_sendrequest(struct smscore_client_t *client,
643                                  void *buffer, size_t size);
644 extern void smscore_onresponse(struct smscore_device_t *coredev,
645                                struct smscore_buffer_t *cb);
646
647 extern int smscore_get_common_buffer_size(struct smscore_device_t *coredev);
648 extern int smscore_map_common_buffer(struct smscore_device_t *coredev,
649                                       struct vm_area_struct *vma);
650 extern int smscore_get_fw_filename(struct smscore_device_t *coredev,
651                                    int mode, char *filename);
652 extern int smscore_send_fw_file(struct smscore_device_t *coredev,
653                                 u8 *ufwbuf, int size);
654
655 extern
656 struct smscore_buffer_t *smscore_getbuffer(struct smscore_device_t *coredev);
657 extern void smscore_putbuffer(struct smscore_device_t *coredev,
658                               struct smscore_buffer_t *cb);
659
660 /* old GPIO managment */
661 int smscore_configure_gpio(struct smscore_device_t *coredev, u32 pin,
662                            struct smscore_config_gpio *pinconfig);
663 int smscore_set_gpio(struct smscore_device_t *coredev, u32 pin, int level);
664
665 /* new GPIO managment */
666 extern int smscore_gpio_configure(struct smscore_device_t *coredev, u8 PinNum,
667                 struct smscore_gpio_config *pGpioConfig);
668 extern int smscore_gpio_set_level(struct smscore_device_t *coredev, u8 PinNum,
669                 u8 NewLevel);
670 extern int smscore_gpio_get_level(struct smscore_device_t *coredev, u8 PinNum,
671                 u8 *level);
672
673 void smscore_set_board_id(struct smscore_device_t *core, int id);
674 int smscore_get_board_id(struct smscore_device_t *core);
675
676 int smscore_led_state(struct smscore_device_t *core, int led);
677
678
679 /* ------------------------------------------------------------------------ */
680
681 #define DBG_INFO 1
682 #define DBG_ADV  2
683
684 #define sms_printk(kern, fmt, arg...) \
685         printk(kern "%s: " fmt "\n", __func__, ##arg)
686
687 #define dprintk(kern, lvl, fmt, arg...) do {\
688         if (sms_dbg & lvl) \
689                 sms_printk(kern, fmt, ##arg); } while (0)
690
691 #define sms_log(fmt, arg...) sms_printk(KERN_INFO, fmt, ##arg)
692 #define sms_err(fmt, arg...) \
693         sms_printk(KERN_ERR, "line: %d: " fmt, __LINE__, ##arg)
694 #define sms_warn(fmt, arg...)  sms_printk(KERN_WARNING, fmt, ##arg)
695 #define sms_info(fmt, arg...) \
696         dprintk(KERN_INFO, DBG_INFO, fmt, ##arg)
697 #define sms_debug(fmt, arg...) \
698         dprintk(KERN_DEBUG, DBG_ADV, fmt, ##arg)
699
700
701 #endif /* __SMS_CORE_API_H__ */