18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef DIBX000_COMMON_H 38c2ecf20Sopenharmony_ci#define DIBX000_COMMON_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_cienum dibx000_i2c_interface { 68c2ecf20Sopenharmony_ci DIBX000_I2C_INTERFACE_TUNER = 0, 78c2ecf20Sopenharmony_ci DIBX000_I2C_INTERFACE_GPIO_1_2 = 1, 88c2ecf20Sopenharmony_ci DIBX000_I2C_INTERFACE_GPIO_3_4 = 2, 98c2ecf20Sopenharmony_ci DIBX000_I2C_INTERFACE_GPIO_6_7 = 3 108c2ecf20Sopenharmony_ci}; 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_cistruct dibx000_i2c_master { 138c2ecf20Sopenharmony_ci#define DIB3000MC 1 148c2ecf20Sopenharmony_ci#define DIB7000 2 158c2ecf20Sopenharmony_ci#define DIB7000P 11 168c2ecf20Sopenharmony_ci#define DIB7000MC 12 178c2ecf20Sopenharmony_ci#define DIB8000 13 188c2ecf20Sopenharmony_ci u16 device_rev; 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci enum dibx000_i2c_interface selected_interface; 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* struct i2c_adapter tuner_i2c_adap; */ 238c2ecf20Sopenharmony_ci struct i2c_adapter gated_tuner_i2c_adap; 248c2ecf20Sopenharmony_ci struct i2c_adapter master_i2c_adap_gpio12; 258c2ecf20Sopenharmony_ci struct i2c_adapter master_i2c_adap_gpio34; 268c2ecf20Sopenharmony_ci struct i2c_adapter master_i2c_adap_gpio67; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci struct i2c_adapter *i2c_adap; 298c2ecf20Sopenharmony_ci u8 i2c_addr; 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci u16 base_reg; 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci /* for the I2C transfer */ 348c2ecf20Sopenharmony_ci struct i2c_msg msg[34]; 358c2ecf20Sopenharmony_ci u8 i2c_write_buffer[8]; 368c2ecf20Sopenharmony_ci u8 i2c_read_buffer[2]; 378c2ecf20Sopenharmony_ci struct mutex i2c_buffer_lock; 388c2ecf20Sopenharmony_ci}; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ciextern int dibx000_init_i2c_master(struct dibx000_i2c_master *mst, 418c2ecf20Sopenharmony_ci u16 device_rev, struct i2c_adapter *i2c_adap, 428c2ecf20Sopenharmony_ci u8 i2c_addr); 438c2ecf20Sopenharmony_ciextern struct i2c_adapter *dibx000_get_i2c_adapter(struct dibx000_i2c_master 448c2ecf20Sopenharmony_ci *mst, 458c2ecf20Sopenharmony_ci enum dibx000_i2c_interface 468c2ecf20Sopenharmony_ci intf, int gating); 478c2ecf20Sopenharmony_ciextern void dibx000_exit_i2c_master(struct dibx000_i2c_master *mst); 488c2ecf20Sopenharmony_ciextern void dibx000_reset_i2c_master(struct dibx000_i2c_master *mst); 498c2ecf20Sopenharmony_ciextern int dibx000_i2c_set_speed(struct i2c_adapter *i2c_adap, u16 speed); 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci#define BAND_LBAND 0x01 528c2ecf20Sopenharmony_ci#define BAND_UHF 0x02 538c2ecf20Sopenharmony_ci#define BAND_VHF 0x04 548c2ecf20Sopenharmony_ci#define BAND_SBAND 0x08 558c2ecf20Sopenharmony_ci#define BAND_FM 0x10 568c2ecf20Sopenharmony_ci#define BAND_CBAND 0x20 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci#define BAND_OF_FREQUENCY(freq_kHz) ((freq_kHz) <= 170000 ? BAND_CBAND : \ 598c2ecf20Sopenharmony_ci (freq_kHz) <= 115000 ? BAND_FM : \ 608c2ecf20Sopenharmony_ci (freq_kHz) <= 250000 ? BAND_VHF : \ 618c2ecf20Sopenharmony_ci (freq_kHz) <= 863000 ? BAND_UHF : \ 628c2ecf20Sopenharmony_ci (freq_kHz) <= 2000000 ? BAND_LBAND : BAND_SBAND ) 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_cistruct dibx000_agc_config { 658c2ecf20Sopenharmony_ci /* defines the capabilities of this AGC-setting - using the BAND_-defines */ 668c2ecf20Sopenharmony_ci u8 band_caps; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci u16 setup; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci u16 inv_gain; 718c2ecf20Sopenharmony_ci u16 time_stabiliz; 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci u8 alpha_level; 748c2ecf20Sopenharmony_ci u16 thlock; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci u8 wbd_inv; 778c2ecf20Sopenharmony_ci u16 wbd_ref; 788c2ecf20Sopenharmony_ci u8 wbd_sel; 798c2ecf20Sopenharmony_ci u8 wbd_alpha; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci u16 agc1_max; 828c2ecf20Sopenharmony_ci u16 agc1_min; 838c2ecf20Sopenharmony_ci u16 agc2_max; 848c2ecf20Sopenharmony_ci u16 agc2_min; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci u8 agc1_pt1; 878c2ecf20Sopenharmony_ci u8 agc1_pt2; 888c2ecf20Sopenharmony_ci u8 agc1_pt3; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci u8 agc1_slope1; 918c2ecf20Sopenharmony_ci u8 agc1_slope2; 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci u8 agc2_pt1; 948c2ecf20Sopenharmony_ci u8 agc2_pt2; 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci u8 agc2_slope1; 978c2ecf20Sopenharmony_ci u8 agc2_slope2; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci u8 alpha_mant; 1008c2ecf20Sopenharmony_ci u8 alpha_exp; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci u8 beta_mant; 1038c2ecf20Sopenharmony_ci u8 beta_exp; 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci u8 perform_agc_softsplit; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci struct { 1088c2ecf20Sopenharmony_ci u16 min; 1098c2ecf20Sopenharmony_ci u16 max; 1108c2ecf20Sopenharmony_ci u16 min_thres; 1118c2ecf20Sopenharmony_ci u16 max_thres; 1128c2ecf20Sopenharmony_ci } split; 1138c2ecf20Sopenharmony_ci}; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_cistruct dibx000_bandwidth_config { 1168c2ecf20Sopenharmony_ci u32 internal; 1178c2ecf20Sopenharmony_ci u32 sampling; 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci u8 pll_prediv; 1208c2ecf20Sopenharmony_ci u8 pll_ratio; 1218c2ecf20Sopenharmony_ci u8 pll_range; 1228c2ecf20Sopenharmony_ci u8 pll_reset; 1238c2ecf20Sopenharmony_ci u8 pll_bypass; 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci u8 enable_refdiv; 1268c2ecf20Sopenharmony_ci u8 bypclk_div; 1278c2ecf20Sopenharmony_ci u8 IO_CLK_en_core; 1288c2ecf20Sopenharmony_ci u8 ADClkSrc; 1298c2ecf20Sopenharmony_ci u8 modulo; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci u16 sad_cfg; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci u32 ifreq; 1348c2ecf20Sopenharmony_ci u32 timf; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci u32 xtal_hz; 1378c2ecf20Sopenharmony_ci}; 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_cienum dibx000_adc_states { 1408c2ecf20Sopenharmony_ci DIBX000_SLOW_ADC_ON = 0, 1418c2ecf20Sopenharmony_ci DIBX000_SLOW_ADC_OFF, 1428c2ecf20Sopenharmony_ci DIBX000_ADC_ON, 1438c2ecf20Sopenharmony_ci DIBX000_ADC_OFF, 1448c2ecf20Sopenharmony_ci DIBX000_VBG_ENABLE, 1458c2ecf20Sopenharmony_ci DIBX000_VBG_DISABLE, 1468c2ecf20Sopenharmony_ci}; 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci#define BANDWIDTH_TO_KHZ(v) ((v) / 1000) 1498c2ecf20Sopenharmony_ci#define BANDWIDTH_TO_HZ(v) ((v) * 1000) 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci/* Chip output mode. */ 1528c2ecf20Sopenharmony_ci#define OUTMODE_HIGH_Z 0 1538c2ecf20Sopenharmony_ci#define OUTMODE_MPEG2_PAR_GATED_CLK 1 1548c2ecf20Sopenharmony_ci#define OUTMODE_MPEG2_PAR_CONT_CLK 2 1558c2ecf20Sopenharmony_ci#define OUTMODE_MPEG2_SERIAL 7 1568c2ecf20Sopenharmony_ci#define OUTMODE_DIVERSITY 4 1578c2ecf20Sopenharmony_ci#define OUTMODE_MPEG2_FIFO 5 1588c2ecf20Sopenharmony_ci#define OUTMODE_ANALOG_ADC 6 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci#define INPUT_MODE_OFF 0x11 1618c2ecf20Sopenharmony_ci#define INPUT_MODE_DIVERSITY 0x12 1628c2ecf20Sopenharmony_ci#define INPUT_MODE_MPEG 0x13 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_cienum frontend_tune_state { 1658c2ecf20Sopenharmony_ci CT_TUNER_START = 10, 1668c2ecf20Sopenharmony_ci CT_TUNER_STEP_0, 1678c2ecf20Sopenharmony_ci CT_TUNER_STEP_1, 1688c2ecf20Sopenharmony_ci CT_TUNER_STEP_2, 1698c2ecf20Sopenharmony_ci CT_TUNER_STEP_3, 1708c2ecf20Sopenharmony_ci CT_TUNER_STEP_4, 1718c2ecf20Sopenharmony_ci CT_TUNER_STEP_5, 1728c2ecf20Sopenharmony_ci CT_TUNER_STEP_6, 1738c2ecf20Sopenharmony_ci CT_TUNER_STEP_7, 1748c2ecf20Sopenharmony_ci CT_TUNER_STOP, 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci CT_AGC_START = 20, 1778c2ecf20Sopenharmony_ci CT_AGC_STEP_0, 1788c2ecf20Sopenharmony_ci CT_AGC_STEP_1, 1798c2ecf20Sopenharmony_ci CT_AGC_STEP_2, 1808c2ecf20Sopenharmony_ci CT_AGC_STEP_3, 1818c2ecf20Sopenharmony_ci CT_AGC_STEP_4, 1828c2ecf20Sopenharmony_ci CT_AGC_STOP, 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci CT_DEMOD_START = 30, 1858c2ecf20Sopenharmony_ci CT_DEMOD_STEP_1, 1868c2ecf20Sopenharmony_ci CT_DEMOD_STEP_2, 1878c2ecf20Sopenharmony_ci CT_DEMOD_STEP_3, 1888c2ecf20Sopenharmony_ci CT_DEMOD_STEP_4, 1898c2ecf20Sopenharmony_ci CT_DEMOD_STEP_5, 1908c2ecf20Sopenharmony_ci CT_DEMOD_STEP_6, 1918c2ecf20Sopenharmony_ci CT_DEMOD_STEP_7, 1928c2ecf20Sopenharmony_ci CT_DEMOD_STEP_8, 1938c2ecf20Sopenharmony_ci CT_DEMOD_STEP_9, 1948c2ecf20Sopenharmony_ci CT_DEMOD_STEP_10, 1958c2ecf20Sopenharmony_ci CT_DEMOD_STEP_11, 1968c2ecf20Sopenharmony_ci CT_DEMOD_SEARCH_NEXT = 51, 1978c2ecf20Sopenharmony_ci CT_DEMOD_STEP_LOCKED, 1988c2ecf20Sopenharmony_ci CT_DEMOD_STOP, 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci CT_DONE = 100, 2018c2ecf20Sopenharmony_ci CT_SHUTDOWN, 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci}; 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_cistruct dvb_frontend_parametersContext { 2068c2ecf20Sopenharmony_ci#define CHANNEL_STATUS_PARAMETERS_UNKNOWN 0x01 2078c2ecf20Sopenharmony_ci#define CHANNEL_STATUS_PARAMETERS_SET 0x02 2088c2ecf20Sopenharmony_ci u8 status; 2098c2ecf20Sopenharmony_ci u32 tune_time_estimation[2]; 2108c2ecf20Sopenharmony_ci s32 tps_available; 2118c2ecf20Sopenharmony_ci u16 tps[9]; 2128c2ecf20Sopenharmony_ci}; 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci#define FE_STATUS_TUNE_FAILED 0 2158c2ecf20Sopenharmony_ci#define FE_STATUS_TUNE_TIMED_OUT -1 2168c2ecf20Sopenharmony_ci#define FE_STATUS_TUNE_TIME_TOO_SHORT -2 2178c2ecf20Sopenharmony_ci#define FE_STATUS_TUNE_PENDING -3 2188c2ecf20Sopenharmony_ci#define FE_STATUS_STD_SUCCESS -4 2198c2ecf20Sopenharmony_ci#define FE_STATUS_FFT_SUCCESS -5 2208c2ecf20Sopenharmony_ci#define FE_STATUS_DEMOD_SUCCESS -6 2218c2ecf20Sopenharmony_ci#define FE_STATUS_LOCKED -7 2228c2ecf20Sopenharmony_ci#define FE_STATUS_DATA_LOCKED -8 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ci#define FE_CALLBACK_TIME_NEVER 0xffffffff 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci#define DATA_BUS_ACCESS_MODE_8BIT 0x01 2278c2ecf20Sopenharmony_ci#define DATA_BUS_ACCESS_MODE_16BIT 0x02 2288c2ecf20Sopenharmony_ci#define DATA_BUS_ACCESS_MODE_NO_ADDRESS_INCREMENT 0x10 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_cistruct dibGPIOFunction { 2318c2ecf20Sopenharmony_ci#define BOARD_GPIO_COMPONENT_BUS_ADAPTER 1 2328c2ecf20Sopenharmony_ci#define BOARD_GPIO_COMPONENT_DEMOD 2 2338c2ecf20Sopenharmony_ci u8 component; 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci#define BOARD_GPIO_FUNCTION_BOARD_ON 1 2368c2ecf20Sopenharmony_ci#define BOARD_GPIO_FUNCTION_BOARD_OFF 2 2378c2ecf20Sopenharmony_ci#define BOARD_GPIO_FUNCTION_COMPONENT_ON 3 2388c2ecf20Sopenharmony_ci#define BOARD_GPIO_FUNCTION_COMPONENT_OFF 4 2398c2ecf20Sopenharmony_ci#define BOARD_GPIO_FUNCTION_SUBBAND_PWM 5 2408c2ecf20Sopenharmony_ci#define BOARD_GPIO_FUNCTION_SUBBAND_GPIO 6 2418c2ecf20Sopenharmony_ci u8 function; 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci/* mask, direction and value are used specify which GPIO to change GPIO0 2448c2ecf20Sopenharmony_ci * is LSB and possible GPIO31 is MSB. The same bit-position as in the 2458c2ecf20Sopenharmony_ci * mask is used for the direction and the value. Direction == 1 is OUT, 2468c2ecf20Sopenharmony_ci * 0 == IN. For direction "OUT" value is either 1 or 0, for direction IN 2478c2ecf20Sopenharmony_ci * value has no meaning. 2488c2ecf20Sopenharmony_ci * 2498c2ecf20Sopenharmony_ci * In case of BOARD_GPIO_FUNCTION_PWM mask is giving the GPIO to be 2508c2ecf20Sopenharmony_ci * used to do the PWM. Direction gives the PWModulator to be used. 2518c2ecf20Sopenharmony_ci * Value gives the PWM value in device-dependent scale. 2528c2ecf20Sopenharmony_ci */ 2538c2ecf20Sopenharmony_ci u32 mask; 2548c2ecf20Sopenharmony_ci u32 direction; 2558c2ecf20Sopenharmony_ci u32 value; 2568c2ecf20Sopenharmony_ci}; 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci#define MAX_NB_SUBBANDS 8 2598c2ecf20Sopenharmony_cistruct dibSubbandSelection { 2608c2ecf20Sopenharmony_ci u8 size; /* Actual number of subbands. */ 2618c2ecf20Sopenharmony_ci struct { 2628c2ecf20Sopenharmony_ci u16 f_mhz; 2638c2ecf20Sopenharmony_ci struct dibGPIOFunction gpio; 2648c2ecf20Sopenharmony_ci } subband[MAX_NB_SUBBANDS]; 2658c2ecf20Sopenharmony_ci}; 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci#define DEMOD_TIMF_SET 0x00 2688c2ecf20Sopenharmony_ci#define DEMOD_TIMF_GET 0x01 2698c2ecf20Sopenharmony_ci#define DEMOD_TIMF_UPDATE 0x02 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci#define MPEG_ON_DIBTX 1 2728c2ecf20Sopenharmony_ci#define DIV_ON_DIBTX 2 2738c2ecf20Sopenharmony_ci#define ADC_ON_DIBTX 3 2748c2ecf20Sopenharmony_ci#define DEMOUT_ON_HOSTBUS 4 2758c2ecf20Sopenharmony_ci#define DIBTX_ON_HOSTBUS 5 2768c2ecf20Sopenharmony_ci#define MPEG_ON_HOSTBUS 6 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci#endif 279