Initial commit
[kernel/linux-3.0.git] / drivers / media / tdmb / mtv318 / raontv_port.h
1 /*
2  *
3  * File name: drivers/media/tdmb/mtv318/src/raontv_port.h
4  *
5  * Description :  RAONTECH TV configuration header file.
6  *
7  * Copyright (C) (2011, RAONTECH)
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation version 2.
12  *
13  * This program is distributed "as is" WITHOUT ANY WARRANTY of any
14  * kind, whether express or implied; without even the implied warranty
15  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  */
19
20 #ifndef __RAONTV_PORT_H__
21 #define __RAONTV_PORT_H__
22
23 /*==============================================================================
24  * Includes the user header files if neccessry.
25  *============================================================================*/
26 #if defined(__KERNEL__) /* Linux kernel */
27 #include <linux/io.h>
28 #include <linux/kernel.h>
29 #include <linux/delay.h>
30 #include <linux/mm.h>
31 #include <linux/mutex.h>
32
33 #elif defined(WINCE)
34 #include <windows.h>
35 #include <drvmsg.h>
36 #endif
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 /*##############################################################################
43  #
44  # COMMON configurations
45  #
46  #############################################################################*/
47 /*==============================================================================
48  * The slave address for I2C and SPI, the base address for EBI2.
49  *============================================================================*/
50 #define RAONTV_CHIP_ADDR        0x86
51
52 /*==============================================================================
53  * Modifies the basic data types if neccessry.
54  *============================================================================*/
55 #define BOOL            int
56 #define S8              s8
57 #define U8              u8
58 #define S16             s16
59 #define U16             u16
60 #define S32             s32
61 #define U32             u32
62
63 #define INT             int
64 #define UINT            unsigned int
65 #define LONG            long
66 #define ULONG           unsigned long
67
68 #define INLINE          inline
69
70 /*==============================================================================
71  * Selects the TV mode(s) to target product.
72  *============================================================================*/
73 /*#define RTV_ISDBT_ENABLE*/
74 #define RTV_TDMB_ENABLE
75 /*#define RTV_FM_ENABLE*/
76 /*#define RTV_DAB_ENABLE*/
77
78 /*==============================================================================
79  * Defines the package type of chip to target product.
80  *============================================================================*/
81 #define RAONTV_CHIP_PKG_WLCSP   /* MTV220/318*/
82 /*#define RAONTV_CHIP_PKG_QFN           // MTV818*/
83 /* #define RAONTV_CHIP_PKG_LGA   MTV250/350 */
84 /*==============================================================================
85  * Defines the external source freqenecy in KHz.
86  * Ex> #define RTV_SRC_CLK_FREQ_KHz     36000 // 36MHz
87  *==============================================================================
88  * MTV250 : #define RTV_SRC_CLK_FREQ_KHz  32000  //must be defined
89  * MTV350 : #define RTV_SRC_CLK_FREQ_KHz  24576  //must be defined
90  *============================================================================*/
91 #define RTV_SRC_CLK_FREQ_KHz                    24576
92
93 /*==============================================================================
94  * Define the power type.
95  *============================================================================*/
96 /*#define RTV_PWR_EXTERNAL*/
97 #define RTV_PWR_LDO
98 /* #define RTV_PWR_DCDC */
99
100 /*==============================================================================
101  * Defines the I/O voltage.
102  *============================================================================*/
103 #define RTV_IO_1_8V
104 /*#define RTV_IO_2_5V*/
105 /*#define RTV_IO_3_3V*/
106
107 #if defined(RTV_IO_2_5V) || defined(RTV_IO_3_3V)
108 #error "If VDDIO pin is connected with IO voltage,"
109         " RTV_IO_1_8V must be defined,please check the HW pin connection"
110 #error "If VDDIO pin is connected with GND,"
111         " IO voltage must be defined same as AP IO voltage"
112 #endif
113
114 /*==============================================================================
115  * Defines the Host interface.
116  *============================================================================*/
117 /*#define RTV_IF_MPEG2_SERIAL_TSIF*/ /* I2C + TSIF Master Mode. */
118 /*#define RTV_IF_MPEG2_PARALLEL_TSIF*/ /* I2C + TSIF Master Mode.
119                                         Support only 1seg &TDMB Application!*/
120 /*#define RTV_IF_QUALCOMM_TSIF*/ /* I2C + TSIF Master Mode */
121 #define RTV_IF_SPI /* AP: SPI Master Mode */
122 /*#define RTV_IF_SPI_SLAVE*/ /* AP: SPI Slave Mode */
123 /*#define RTV_IF_EBI2*/ /* External Bus Interface Slave Mode */
124
125 /*==============================================================================
126  * Defines the clear mode of interrupts for EBI/SPI in Individual mode .
127  *============================================================================*/
128 #define RTV_MSC_INTR_ISTAUS_ACC_CLR_MODE /* for Nested ISR and TSIF. */
129 /* #define RTV_MSC_INTR_MEM_ACC_CLR_MODE */ /* for NOT nested ISR.*/
130
131 /*==============================================================================
132  * Defines the delay macro in milliseconds.
133  *============================================================================*/
134 #if defined(__KERNEL__)/* Linux kernel */
135 #define RTV_DELAY_MS(ms)        mdelay(ms)
136
137 #elif defined(WINCE)
138 #define RTV_DELAY_MS(ms)        Sleep(ms)
139
140 #else
141 extern void mtv818_delay_ms(int ms);
142 #define RTV_DELAY_MS(ms)        mtv818_delay_ms(ms) /* TODO */
143 #endif
144
145 /*==============================================================================
146  * Defines the debug message macro.
147  *============================================================================*/
148 #if 1
149 #define RTV_DBGMSG0(fmt)                                        printk(fmt)
150 #define RTV_DBGMSG1(fmt, arg1)                          printk(fmt, arg1)
151 #define RTV_DBGMSG2(fmt, arg1, arg2)            printk(fmt, arg1, arg2)
152 #define RTV_DBGMSG3(fmt, arg1, arg2, arg3)      printk(fmt, arg1, arg2, arg3)
153 #else
154 /* To eliminates the debug messages. */
155 #define RTV_DBGMSG0(fmt)                                        ((void)0)
156 #define RTV_DBGMSG1(fmt, arg1)                          ((void)0)
157 #define RTV_DBGMSG2(fmt, arg1, arg2)            ((void)0)
158 #define RTV_DBGMSG3(fmt, arg1, arg2, arg3)      ((void)0)
159 #endif
160 /*#### End of Common ###########*/
161
162 /*##############################################################################
163  #
164  # ISDB-T specific configurations
165  #
166  #############################################################################*/
167 /*==============================================================================
168  * Defines the NOTCH FILTER setting Enable.
169  * In order to reject GSM/CDMA blocker, NOTCH FILTER must be defined.
170  * This feature used for module company in the JAPAN.
171  *============================================================================*/
172 /*
173 //#if defined(RTV_ISDBT_ENABLE)  //Do not use
174 //      #ifdef RAONTV_CHIP_PKG_WLCSP
175 //      #define RTV_NOTCH_FILTER_ENABLE
176 //      #endif
177 //#endif
178 */
179 /*##############################################################################
180  #
181  # T-DMB/DAB specific configurations
182  #
183  #############################################################################*/
184 #if defined(RTV_TDMB_ENABLE) || defined(RTV_DAB_ENABLE)
185 #define RTV_FIC_POLLING_MODE
186
187 /* Defines the maximum number of Sub Channel to be open simultaneously. */
188 #define RTV_MAX_NUM_SUB_CHANNEL_USED            1
189
190 /* Defines CIF or Individual Mode for T-DMB/DAB BY RAONTECH. */
191 /*#define RTV_CIF_MODE_ENABLED*/
192 /*#define RTV_CIF_HEADER_INSERTED*/
193 /* Select the copying method of CIF decoded data(FIC and MSC)
194         which copy_to_user() or memcpy() to fast operation for LINUX Kernel. */
195 /*#define RTV_CIF_LINUX_USER_SPACE_COPY_USED*/
196 #endif /* #if defined(RTV_TDMB_ENABLE) || defined(RTV_DAB_ENABLE)  */
197
198 /*##############################################################################
199  #
200  # FM specific configurations
201  #
202  #############################################################################*/
203 #define RTV_FM_CH_MIN_FREQ_KHz          76000
204 #define RTV_FM_CH_MAX_FREQ_KHz          108000
205 #define RTV_FM_CH_STEP_FREQ_KHz         100 /* in KHz */
206 /*##############################################################################
207  #
208  # Host Interface specific configurations
209  #
210  #############################################################################*/
211 #if defined(RTV_IF_MPEG2_SERIAL_TSIF) || defined(RTV_IF_QUALCOMM_TSIF) \
212         || defined(RTV_IF_MPEG2_PARALLEL_TSIF)
213 #define RTV_IF_TSIF
214 #endif
215
216 #if defined(RTV_IF_MPEG2_SERIAL_TSIF) || defined(RTV_IF_QUALCOMM_TSIF)
217         #define RTV_IF_SERIAL_TSIF
218 #endif
219
220
221 #if defined(RTV_IF_TSIF) || defined(RTV_IF_SPI_SLAVE)
222 /*==============================================================================
223  * Defines the TSIF interface for MPEG2 or QUALCOMM TSIF.
224  *============================================================================*/
225 /*#define RTV_TSIF_FORMAT_1*/
226 /*#define RTV_TSIF_FORMAT_2*/
227 #define RTV_TSIF_FORMAT_3
228 /*#define RTV_TSIF_FORMAT_4*/
229 /*#define RTV_TSIF_FORMAT_5*/
230
231 /*#define RTV_TSIF_CLK_SPEED_DIV_2 // Host Clk/2*/
232 #define RTV_TSIF_CLK_SPEED_DIV_4 /* Host Clk/4 */
233 /*#define RTV_TSIF_CLK_SPEED_DIV_6 // Host Clk/6*/
234 /*#define RTV_TSIF_CLK_SPEED_DIV_8 // Host Clk/8*/
235
236 /*==========================================================================
237  * Defines the register I/O macros.
238  *========================================================================*/
239 unsigned char mtv818_i2c_read(U8 reg);
240 void mtv818_i2c_read_burst(U8 reg, U8 *buf, int size);
241 void mtv818_i2c_write(U8 reg, U8 val);
242 #define RTV_REG_GET(reg) \
243         mtv818_i2c_read((U8)(reg))
244 #define RTV_REG_BURST_GET(reg, buf, size) \
245         mtv818_i2c_read_burst((U8)(reg), buf, size)
246 #define RTV_REG_SET(reg, val) \
247         mtv818_i2c_write((U8)(reg), (U8)(val))
248 #define RTV_REG_MASK_SET(reg, mask, val)\
249 do { \
250         U8 tmp; \
251         tmp = (RTV_REG_GET(reg)|(U8)(mask)) & (U8)((~(mask))|(val)); \
252         RTV_REG_SET(reg, tmp); \
253 } while (0)
254
255 #elif defined(RTV_IF_SPI)
256 /*=========================================================================
257  * Defines the register I/O macros.
258  *========================================================================*/
259 unsigned char mtv_spi_read(unsigned char reg);
260 void mtv_spi_read_burst(unsigned char reg, unsigned char *buf, int size);
261 void mtv_spi_write(unsigned char reg, unsigned char val);
262
263 #define RTV_REG_GET(reg) \
264         (U8)mtv_spi_read((U8)(reg))
265 #define RTV_REG_BURST_GET(reg, buf, size) \
266         mtv_spi_read_burst((U8)(reg), buf, size)
267 #define RTV_REG_SET(reg, val) \
268         mtv_spi_write((U8)(reg), (U8)(val))
269 #define RTV_REG_MASK_SET(reg, mask, val) \
270 do { \
271         U8 tmp; \
272         tmp = (RTV_REG_GET(reg)|(U8)(mask)) & (U8)((~(mask))|(val)); \
273         RTV_REG_SET(reg, tmp); \
274 } while (0)
275
276
277
278 #else
279 #error "Must define the interface definition !"
280 #endif
281
282 #if defined(RTV_IF_SPI) \
283         || ((defined(RTV_TDMB_ENABLE) || defined(RTV_DAB_ENABLE)) \
284         && !defined(RTV_FIC_POLLING_MODE))
285 #if defined(__KERNEL__)
286 extern struct mutex raontv_guard;
287 #define RTV_GUARD_INIT          mutex_init(&raontv_guard)
288 #define RTV_GUARD_LOCK          mutex_lock(&raontv_guard)
289 #define RTV_GUARD_FREE          mutex_unlock(&raontv_guard)
290 #define RTV_GUARD_DEINIT        ((void)0)
291
292 #elif defined(WINCE)
293 extern CRITICAL_SECTION raontv_guard;
294 #define RTV_GUARD_INIT      InitializeCriticalSection(&raontv_guard)
295 #define RTV_GUARD_LOCK      EnterCriticalSection(&raontv_guard)
296 #define RTV_GUARD_FREE      LeaveCriticalSection(&raontv_guard)
297 #define RTV_GUARD_DEINIT    DeleteCriticalSection(&raontv_guard)
298 #else
299 /* temp: TODO */
300 #define RTV_GUARD_INIT          ((void)0)
301 #define RTV_GUARD_LOCK          ((void)0)
302 #define RTV_GUARD_FREE  ((void)0)
303 #define RTV_GUARD_DEINIT        ((void)0)
304 #endif
305
306 #else
307 #define RTV_GUARD_INIT          ((void)0)
308 #define RTV_GUARD_LOCK          ((void)0)
309 #define RTV_GUARD_FREE  ((void)0)
310 #define RTV_GUARD_DEINIT        ((void)0)
311 #endif
312
313 #if defined(RTV_IF_TSIF) || defined(RTV_IF_SPI_SLAVE)\
314 || defined(__KERNEL__) || defined(WINCE)
315         #ifdef RTV_MSC_INTR_MEM_ACC_CLR_MODE
316         #undef RTV_MSC_INTR_MEM_ACC_CLR_MODE
317         #endif
318
319         #ifndef RTV_MSC_INTR_ISTAUS_ACC_CLR_MODE
320         #define RTV_MSC_INTR_ISTAUS_ACC_CLR_MODE
321         #endif
322 #endif
323
324
325 /*==============================================================================
326  * Check erros
327  *============================================================================*/
328 #if !defined(RAONTV_CHIP_PKG_WLCSP) \
329         && !defined(RAONTV_CHIP_PKG_QFN) \
330         && !defined(RAONTV_CHIP_PKG_LGA)
331 #error "Must define the package type !"
332 #endif
333
334 #if !defined(RTV_PWR_EXTERNAL) \
335         && !defined(RTV_PWR_LDO) \
336         && !defined(RTV_PWR_DCDC)
337 #error "Must define the power type !"
338 #endif
339
340 #if !defined(RTV_IO_1_8V) \
341         && !defined(RTV_IO_2_5V) \
342         && !defined(RTV_IO_3_3V)
343 #error "Must define I/O voltage!"
344 #endif
345
346 #if defined(RTV_IF_MPEG2_SERIAL_TSIF) \
347         || defined(RTV_IF_SPI_SLAVE) \
348         || defined(RTV_IF_MPEG2_PARALLEL_TSIF) \
349         || defined(RTV_IF_QUALCOMM_TSIF) \
350         || defined(RTV_IF_SPI)
351 #if (RAONTV_CHIP_ADDR >= 0xFF)
352 #error "Invalid chip address"
353 #endif
354 #elif defined(RTV_IF_EBI2)
355 #if (RAONTV_CHIP_ADDR <= 0xFF)
356 #error "Invalid chip address"
357 #endif
358
359 #else
360 #error "Must define the interface definition !"
361 #endif
362
363 #if defined(RTV_TDMB_ENABLE) || defined(RTV_DAB_ENABLE)
364 #ifndef RTV_MAX_NUM_SUB_CHANNEL_USED
365 #error "Should be define!"
366 #endif
367
368 #if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)
369 #if (RTV_MAX_NUM_SUB_CHANNEL_USED < 0) || (RTV_MAX_NUM_SUB_CHANNEL_USED > 5)
370 #error "Must from 1 to 5"
371 #endif
372 #else
373 #if (RTV_MAX_NUM_SUB_CHANNEL_USED < 0) || (RTV_MAX_NUM_SUB_CHANNEL_USED > 4)
374 #error "Must from 1 to 4"
375 #endif
376 #endif
377 #else
378 #ifdef RTV_MAX_NUM_SUB_CHANNEL_USED
379 #undef RTV_MAX_NUM_SUB_CHANNEL_USED
380 #define RTV_MAX_NUM_SUB_CHANNEL_USED            1 /* To not make error. */
381 #else
382 #define RTV_MAX_NUM_SUB_CHANNEL_USED            1
383 #endif
384 #endif
385
386 #ifdef RTV_IF_MPEG2_PARALLEL_TSIF
387 #if defined(RTV_FM_ENABLE) \
388         || defined(RTV_DAB_ENABLE) \
389         || defined(RAONTV_CHIP_PKG_WLCSP) \
390         || defined(RAONTV_CHIP_PKG_LGA)
391 #error "Not support parallel TSIF!"
392 #endif
393
394 #if defined(RTV_TDMB_ENABLE) && (RTV_MAX_NUM_SUB_CHANNEL_USED > 1)
395 #error "Not support T-DMB multi sub channel mode!"
396 #endif
397
398 #if defined(RTV_DAB_ENABLE) && (RTV_MAX_NUM_SUB_CHANNEL_USED > 1)
399 #error "Not support DAB multi sub channel mode!"
400 #endif
401 #endif
402
403 #if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)
404 #if !defined(RTV_MSC_INTR_MEM_ACC_CLR_MODE) \
405         && !defined(RTV_MSC_INTR_ISTAUS_ACC_CLR_MODE)
406 #error " Should selects an interrupt clear mode"
407 #endif
408
409 #if defined(RTV_MSC_INTR_MEM_ACC_CLR_MODE) \
410         && defined(RTV_MSC_INTR_ISTAUS_ACC_CLR_MODE)
411 #error " Should selects an interrupt clear mode"
412 #endif
413 #endif
414
415 #if defined(RTV_DAB_ENABLE) && defined(RTV_TDMB_ENABLE)
416 #error "Should select RTV_DAB_ENABLE(B3, L-BAND, B3-Korea) "
417         "or RTV_TDMB_ENABLE(B3-Korea)"
418 #endif
419
420 #if defined(RTV_CIF_HEADER_INSERTED) && !defined(RTV_CIF_MODE_ENABLED)
421 #error "Should defines RTV_CIF_MODE_ENABLED"
422 #endif
423
424 void rtvOEM_ConfigureInterrupt(void);
425 void rtvOEM_PowerOn(int on);
426
427 #ifdef __cplusplus
428 }
429 #endif
430
431 #endif /* __RAONTV_PORT_H__ */
432