• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * include/linux/amlogic/aml_demod_common.h
3  *
4  * Copyright (C) 2017 Amlogic, Inc. All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  *
16  */
17 
18 #ifndef __AML_DEMOD_COMMON_H__
19 #define __AML_DEMOD_COMMON_H__
20 
21 #include <linux/i2c.h>
22 #include <uapi/linux/videodev2.h>
23 #include <linux/module.h>
24 #include <linux/device.h>
25 #include <linux/platform_device.h>
26 #include <linux/of_gpio.h>
27 #include <linux/dvb/frontend.h>
28 
29 enum tuner_type {
30 	AM_TUNER_NONE = 0,
31 	AM_TUNER_SI2176 = 1,
32 	AM_TUNER_SI2196 = 2,
33 	AM_TUNER_FQ1216 = 3,
34 	AM_TUNER_HTM = 4,
35 	AM_TUNER_CTC703 = 5,
36 	AM_TUNER_SI2177 = 6,
37 	AM_TUNER_R840 = 7,
38 	AM_TUNER_SI2157 = 8,
39 	AM_TUNER_SI2151 = 9,
40 	AM_TUNER_MXL661 = 10,
41 	AM_TUNER_MXL608 = 11,
42 	AM_TUNER_SI2159 = 12,
43 	AM_TUNER_R842 = 13,
44 	AM_TUNER_ATBM2040 = 14,
45 	AM_TUNER_ATBM253 = 15,
46 	AM_TUNER_SI2124 = 16,
47 	AM_TUNER_AV2011 = 17,
48 	AM_TUNER_AV2012 = 18,
49 	AM_TUNER_AV2018 = 19,
50 	AM_TUNER_R836 = 20,
51 	AM_TUNER_R848 = 21,
52 	AM_TUNER_MXL603 = 22
53 };
54 
55 enum atv_demod_type {
56 	AM_ATV_DEMOD_NONE   = 0,
57 	AM_ATV_DEMOD_SI2176 = 1,
58 	AM_ATV_DEMOD_SI2196 = 2,
59 	AM_ATV_DEMOD_FQ1216 = 3,
60 	AM_ATV_DEMOD_HTM    = 4,
61 	AM_ATV_DEMOD_CTC703 = 5,
62 	AM_ATV_DEMOD_SI2177 = 6,
63 	AM_ATV_DEMOD_AMLATV = 7
64 };
65 
66 enum dtv_demod_type {
67 	AM_DTV_DEMOD_NONE     = 0,
68 	AM_DTV_DEMOD_AMLDTV   = 1,
69 	AM_DTV_DEMOD_M1       = 2,
70 	AM_DTV_DEMOD_MXL101   = 3,
71 	AM_DTV_DEMOD_AVL6211  = 4,
72 	AM_DTV_DEMOD_SI2168   = 5,
73 	AM_DTV_DEMOD_ITE9133  = 6,
74 	AM_DTV_DEMOD_ITE9173  = 7,
75 	AM_DTV_DEMOD_DIB8096  = 8,
76 	AM_DTV_DEMOD_ATBM8869 = 9,
77 	AM_DTV_DEMOD_MXL241   = 10,
78 	AM_DTV_DEMOD_AVL68xx  = 11,
79 	AM_DTV_DEMOD_MXL683   = 12,
80 	AM_DTV_DEMOD_ATBM8881 = 13,
81 	AM_DTV_DEMOD_ATBM7821 = 14,
82 	AM_DTV_DEMOD_AVL6762  = 15,
83 	AM_DTV_DEMOD_CXD2856  = 16,
84 	AM_DTV_DEMOD_MXL248   = 17,
85 	AM_DTV_DEMOD_M88DM6K  = 18,
86 	AM_DTV_DEMOD_MN88436  = 19
87 };
88 
89 enum aml_fe_dev_type {
90 	AM_DEV_TUNER,
91 	AM_DEV_ATV_DEMOD,
92 	AM_DEV_DTV_DEMOD
93 };
94 
95 /* For configure gpio */
96 struct gpio_config {
97 	s32 pin; /* gpio pin */
98 	u8 dir; /* direction, 0: out, 1: in. */
99 	u32 value; /* input or output active value */
100 	u32 reserved0;
101 	u32 reserved1;
102 };
103 
104 /* For configure different tuners */
105 /* It can add fields as extensions */
106 struct tuner_config {
107 	u32 code; /* tuner chip code */
108 	u8 id; /* enum tuner type */
109 	u8 i2c_addr;
110 	u8 i2c_id;
111 	struct i2c_adapter *i2c_adap;
112 	u8 xtal; /* 0: 16MHz, 1: 24MHz, 3: 27MHz */
113 	u32 xtal_cap; /* load capacitor */
114 	u8 xtal_mode;
115 	u8 lt_out; /* loop through out, 0: off, 1: on. */
116 	u8 dual_power; /* 0: 3.3v, 1: 1.8v and 3.3v. */
117 	u8 if_agc; /* 0: self, 1: external. */
118 
119 	/* tuner reset gpio, it can be implemented by RC circuit. */
120 	struct gpio_config reset;
121 
122 	u32 reserved0;
123 	u32 reserved1;
124 };
125 
126 /* For configure different demod */
127 struct demod_config {
128 	u32 code; /* demod chip code */
129 	u8 id; /* enum demod type */
130 	u8 mode; /* 0: internal, 1: external */
131 	u8 xtal; /* demod xtal */
132 	u8 ts; /* ts port */
133 	u8 ts_out_mode; /* serial or parallel; 0:serial, 1:parallel */
134 	u8 ts_data_pin; /* serial output pin of TS data */
135 
136 	/* ts output clock, 0: self-adaption, clock frequency
137 	 * is set according to the output bit rate.
138 	 */
139 	u32 ts_clk;
140 
141 	/* ts clock inversion setting
142 	 * 0: Falling / Negative edge.
143 	 * 1: Rising / Positive edge.
144 	 */
145 	u8 ts_clk_mode;
146 
147 	u8 i2c_addr;
148 	u8 i2c_id;
149 	struct i2c_adapter *i2c_adap;
150 
151 	struct tuner_config tuner0; /* TC */
152 	struct tuner_config tuner1; /* S */
153 
154 	struct gpio_config reset;
155 	struct gpio_config ant_power;
156 	struct gpio_config other;
157 
158 	u8 reserved0;
159 	u8 reserved1;
160 };
161 
162 /* For configure multi-tuner */
163 struct aml_tuner {
164 	struct tuner_config cfg;
165 	unsigned int i2c_adapter_id;
166 };
167 
168 /** generic AML DVB attach function. */
169 #if (defined CONFIG_AMLOGIC_DVB_EXTERN)
170 #define aml_dvb_attach(FUNCTION, ARGS...) ({ \
171 	void *__r = NULL; \
172 	typeof(&FUNCTION) __a = symbol_request(FUNCTION); \
173 	if (__a) { \
174 		__r = (void *) __a(ARGS); \
175 		if (__r == NULL) \
176 			symbol_put(FUNCTION); \
177 	} else { \
178 		printk(KERN_ERR "AML DVB: Unable to find symbol " \
179 			#FUNCTION"()\n"); \
180 	} \
181 	__r; \
182 })
183 
184 #define aml_dvb_detach(FUNC) symbol_put_addr(FUNC)
185 
186 #define AML_DEMOD_ATTACH_FUNCTION(name) \
187 static inline struct dvb_frontend *name##_attach(\
188 		const struct demod_config *cfg)\
189 {\
190 	return NULL;\
191 }
192 
193 #define AML_TUNER_ATTACH_FUNCTION(name) \
194 static inline struct dvb_frontend *name##_attach(struct dvb_frontend *fe,\
195 		const struct tuner_config *cfg)\
196 {\
197 	return NULL;\
198 }
199 
200 #else
201 #define aml_dvb_attach(FUNCTION, ARGS...) ({ \
202 	FUNCTION(ARGS); \
203 })
204 
205 #define aml_dvb_detach(FUNC) {}
206 
207 #define AML_DEMOD_ATTACH_FUNCTION(name)
208 
209 #define AML_TUNER_ATTACH_FUNCTION(name)
210 #endif
211 
212 /*COLOR MODULATION TYPE*/
213 #define V4L2_COLOR_STD_PAL    ((v4l2_std_id) 0x04000000)
214 #define V4L2_COLOR_STD_NTSC   ((v4l2_std_id) 0x08000000)
215 #define V4L2_COLOR_STD_SECAM  ((v4l2_std_id) 0x10000000)
216 
217 #if (defined CONFIG_AMLOGIC_DVB_EXTERN)
218 const char *v4l2_std_to_str(v4l2_std_id std);
219 
220 void aml_ktime_get_ts(struct timespec *ts);
221 
222 bool aml_gpio_is_valid(int number);
223 int aml_gpio_get_value(int gpio);
224 void aml_gpio_set_value(int gpio, int value);
225 void aml_gpio_free(int gpio);
226 int aml_gpio_request(int gpio, const char *label);
227 int aml_demod_gpio_set(int gpio, int dir, int value, const char *label);
228 int aml_demod_gpio_config(struct gpio_config *cfg, const char *label);
229 
230 struct class *aml_class_create(struct module *owner, const char *name);
231 void aml_class_destroy(struct class *cls);
232 int aml_class_create_file(struct class *class,
233 		const struct class_attribute *attr);
234 int aml_class_register(struct class *class);
235 void aml_class_unregister(struct class *class);
236 
237 int aml_platform_driver_register(struct platform_driver *drv);
238 void aml_platform_driver_unregister(struct platform_driver *drv);
239 int aml_platform_device_register(struct platform_device *pdev);
240 void aml_platform_device_unregister(struct platform_device *pdev);
241 #else
v4l2_std_to_str(v4l2_std_id std)242 static inline __maybe_unused const char *v4l2_std_to_str(v4l2_std_id std)
243 {
244 	return NULL;
245 }
246 
aml_ktime_get_ts(struct timespec * ts)247 static inline __maybe_unused void aml_ktime_get_ts(struct timespec *ts)
248 {
249 
250 }
251 
aml_gpio_is_valid(int number)252 static inline __maybe_unused bool aml_gpio_is_valid(int number)
253 {
254 	return false;
255 }
256 
aml_gpio_get_value(int gpio)257 static inline __maybe_unused int aml_gpio_get_value(int gpio)
258 {
259 	return 0;
260 }
261 
aml_gpio_set_value(int gpio,int value)262 static inline __maybe_unused void aml_gpio_set_value(int gpio, int value)
263 {
264 }
265 
aml_gpio_free(int gpio)266 static inline __maybe_unused void aml_gpio_free(int gpio)
267 {
268 }
269 
aml_gpio_request(int gpio,const char * label)270 static inline __maybe_unused int aml_gpio_request(int gpio, const char *label)
271 {
272 	return 0;
273 }
274 
aml_demod_gpio_set(int gpio,int dir,int value,const char * label)275 static inline __maybe_unused int aml_demod_gpio_set(int gpio, int dir,
276 		int value, const char *label)
277 {
278 	return 0;
279 }
280 
aml_demod_gpio_config(struct gpio_config * cfg,const char * label)281 static inline __maybe_unused int aml_demod_gpio_config(struct gpio_config *cfg,
282 		const char *label)
283 {
284 	return 0;
285 }
286 
aml_class_create(struct module * owner,const char * name)287 static inline __maybe_unused struct class *aml_class_create(
288 		struct module *owner, const char *name)
289 {
290 	return NULL;
291 }
292 
aml_class_destroy(struct class * cls)293 static inline __maybe_unused void aml_class_destroy(struct class *cls)
294 {
295 }
296 
aml_class_create_file(struct class * class,const struct class_attribute * attr)297 static inline __maybe_unused int aml_class_create_file(struct class *class,
298 		const struct class_attribute *attr)
299 {
300 	return 0;
301 }
302 
aml_class_register(struct class * class)303 static inline __maybe_unused int aml_class_register(struct class *class)
304 {
305 	return 0;
306 }
307 
aml_class_unregister(struct class * class)308 static inline __maybe_unused void aml_class_unregister(struct class *class)
309 {
310 }
311 
aml_platform_driver_register(struct platform_driver * drv)312 static inline __maybe_unused int aml_platform_driver_register(
313 		struct platform_driver *drv)
314 {
315 	return 0;
316 }
317 
aml_platform_driver_unregister(struct platform_driver * drv)318 static inline __maybe_unused void aml_platform_driver_unregister(
319 		struct platform_driver *drv)
320 {
321 }
322 
aml_platform_device_register(struct platform_device * pdev)323 static inline __maybe_unused int aml_platform_device_register(
324 		struct platform_device *pdev)
325 {
326 	return 0;
327 }
328 
aml_platform_device_unregister(struct platform_device * pdev)329 static inline __maybe_unused void aml_platform_device_unregister(
330 		struct platform_device *pdev)
331 {
332 }
333 
334 #endif
335 
336 #endif /* __AML_DEMOD_COMMON_H__ */
337