18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci /* 38c2ecf20Sopenharmony_ci Driver for Philips tda1004xh OFDM Frontend 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci (c) 2004 Andrew de Quincey 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef TDA1004X_H 118c2ecf20Sopenharmony_ci#define TDA1004X_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/dvb/frontend.h> 148c2ecf20Sopenharmony_ci#include <linux/firmware.h> 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_cienum tda10046_xtal { 178c2ecf20Sopenharmony_ci TDA10046_XTAL_4M, 188c2ecf20Sopenharmony_ci TDA10046_XTAL_16M, 198c2ecf20Sopenharmony_ci}; 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_cienum tda10046_agc { 228c2ecf20Sopenharmony_ci TDA10046_AGC_DEFAULT, /* original configuration */ 238c2ecf20Sopenharmony_ci TDA10046_AGC_IFO_AUTO_NEG, /* IF AGC only, automatic, negative */ 248c2ecf20Sopenharmony_ci TDA10046_AGC_IFO_AUTO_POS, /* IF AGC only, automatic, positive */ 258c2ecf20Sopenharmony_ci TDA10046_AGC_TDA827X, /* IF AGC only, special setup for tda827x */ 268c2ecf20Sopenharmony_ci}; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/* Many (hybrid) boards use GPIO 1 and 3 298c2ecf20Sopenharmony_ci GPIO1 analog - dvb switch 308c2ecf20Sopenharmony_ci GPIO3 firmware eeprom address switch 318c2ecf20Sopenharmony_ci*/ 328c2ecf20Sopenharmony_cienum tda10046_gpio { 338c2ecf20Sopenharmony_ci TDA10046_GPTRI = 0x00, /* All GPIOs tristate */ 348c2ecf20Sopenharmony_ci TDA10046_GP00 = 0x40, /* GPIO3=0, GPIO1=0 */ 358c2ecf20Sopenharmony_ci TDA10046_GP01 = 0x42, /* GPIO3=0, GPIO1=1 */ 368c2ecf20Sopenharmony_ci TDA10046_GP10 = 0x48, /* GPIO3=1, GPIO1=0 */ 378c2ecf20Sopenharmony_ci TDA10046_GP11 = 0x4a, /* GPIO3=1, GPIO1=1 */ 388c2ecf20Sopenharmony_ci TDA10046_GP00_I = 0x80, /* GPIO3=0, GPIO1=0, invert in sleep mode*/ 398c2ecf20Sopenharmony_ci TDA10046_GP01_I = 0x82, /* GPIO3=0, GPIO1=1, invert in sleep mode */ 408c2ecf20Sopenharmony_ci TDA10046_GP10_I = 0x88, /* GPIO3=1, GPIO1=0, invert in sleep mode */ 418c2ecf20Sopenharmony_ci TDA10046_GP11_I = 0x8a, /* GPIO3=1, GPIO1=1, invert in sleep mode */ 428c2ecf20Sopenharmony_ci}; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cienum tda10046_if { 458c2ecf20Sopenharmony_ci TDA10046_FREQ_3617, /* original config, 36,166 MHZ */ 468c2ecf20Sopenharmony_ci TDA10046_FREQ_3613, /* 36,13 MHZ */ 478c2ecf20Sopenharmony_ci TDA10046_FREQ_045, /* low IF, 4.0, 4.5, or 5.0 MHZ */ 488c2ecf20Sopenharmony_ci TDA10046_FREQ_052, /* low IF, 5.1667 MHZ for tda9889 */ 498c2ecf20Sopenharmony_ci}; 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_cienum tda10046_tsout { 528c2ecf20Sopenharmony_ci TDA10046_TS_PARALLEL = 0x00, /* parallel transport stream, default */ 538c2ecf20Sopenharmony_ci TDA10046_TS_SERIAL = 0x01, /* serial transport stream */ 548c2ecf20Sopenharmony_ci}; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_cistruct tda1004x_config 578c2ecf20Sopenharmony_ci{ 588c2ecf20Sopenharmony_ci /* the demodulator's i2c address */ 598c2ecf20Sopenharmony_ci u8 demod_address; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci /* does the "inversion" need inverted? */ 628c2ecf20Sopenharmony_ci u8 invert; 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci /* Does the OCLK signal need inverted? */ 658c2ecf20Sopenharmony_ci u8 invert_oclk; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci /* parallel or serial transport stream */ 688c2ecf20Sopenharmony_ci enum tda10046_tsout ts_mode; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci /* Xtal frequency, 4 or 16MHz*/ 718c2ecf20Sopenharmony_ci enum tda10046_xtal xtal_freq; 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci /* IF frequency */ 748c2ecf20Sopenharmony_ci enum tda10046_if if_freq; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci /* AGC configuration */ 778c2ecf20Sopenharmony_ci enum tda10046_agc agc_config; 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci /* setting of GPIO1 and 3 */ 808c2ecf20Sopenharmony_ci enum tda10046_gpio gpio_config; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci /* slave address and configuration of the tuner */ 838c2ecf20Sopenharmony_ci u8 tuner_address; 848c2ecf20Sopenharmony_ci u8 antenna_switch; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci /* if the board uses another I2c Bridge (tda8290), its address */ 878c2ecf20Sopenharmony_ci u8 i2c_gate; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci /* request firmware for device */ 908c2ecf20Sopenharmony_ci int (*request_firmware)(struct dvb_frontend* fe, const struct firmware **fw, char* name); 918c2ecf20Sopenharmony_ci}; 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_cienum tda1004x_demod { 948c2ecf20Sopenharmony_ci TDA1004X_DEMOD_TDA10045, 958c2ecf20Sopenharmony_ci TDA1004X_DEMOD_TDA10046, 968c2ecf20Sopenharmony_ci}; 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_cistruct tda1004x_state { 998c2ecf20Sopenharmony_ci struct i2c_adapter* i2c; 1008c2ecf20Sopenharmony_ci const struct tda1004x_config* config; 1018c2ecf20Sopenharmony_ci struct dvb_frontend frontend; 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci /* private demod data */ 1048c2ecf20Sopenharmony_ci enum tda1004x_demod demod_type; 1058c2ecf20Sopenharmony_ci}; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci#if IS_REACHABLE(CONFIG_DVB_TDA1004X) 1088c2ecf20Sopenharmony_ciextern struct dvb_frontend* tda10045_attach(const struct tda1004x_config* config, 1098c2ecf20Sopenharmony_ci struct i2c_adapter* i2c); 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ciextern struct dvb_frontend* tda10046_attach(const struct tda1004x_config* config, 1128c2ecf20Sopenharmony_ci struct i2c_adapter* i2c); 1138c2ecf20Sopenharmony_ci#else 1148c2ecf20Sopenharmony_cistatic inline struct dvb_frontend* tda10045_attach(const struct tda1004x_config* config, 1158c2ecf20Sopenharmony_ci struct i2c_adapter* i2c) 1168c2ecf20Sopenharmony_ci{ 1178c2ecf20Sopenharmony_ci printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 1188c2ecf20Sopenharmony_ci return NULL; 1198c2ecf20Sopenharmony_ci} 1208c2ecf20Sopenharmony_cistatic inline struct dvb_frontend* tda10046_attach(const struct tda1004x_config* config, 1218c2ecf20Sopenharmony_ci struct i2c_adapter* i2c) 1228c2ecf20Sopenharmony_ci{ 1238c2ecf20Sopenharmony_ci printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 1248c2ecf20Sopenharmony_ci return NULL; 1258c2ecf20Sopenharmony_ci} 1268c2ecf20Sopenharmony_ci#endif // CONFIG_DVB_TDA1004X 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_cistatic inline int tda1004x_writereg(struct dvb_frontend *fe, u8 reg, u8 val) { 1298c2ecf20Sopenharmony_ci int r = 0; 1308c2ecf20Sopenharmony_ci u8 buf[] = {reg, val}; 1318c2ecf20Sopenharmony_ci if (fe->ops.write) 1328c2ecf20Sopenharmony_ci r = fe->ops.write(fe, buf, 2); 1338c2ecf20Sopenharmony_ci return r; 1348c2ecf20Sopenharmony_ci} 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci#endif // TDA1004X_H 137