18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* DVB USB framework compliant Linux driver for the HanfTek UMT-010 USB2.0 38c2ecf20Sopenharmony_ci * DVB-T receiver. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@posteo.de) 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * see Documentation/driver-api/media/drivers/dvb-usb.rst for more information 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci#include "dibusb.h" 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include "mt352.h" 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ciDVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_cistatic int umt_mt352_demod_init(struct dvb_frontend *fe) 168c2ecf20Sopenharmony_ci{ 178c2ecf20Sopenharmony_ci static u8 mt352_clock_config[] = { 0x89, 0xb8, 0x2d }; 188c2ecf20Sopenharmony_ci static u8 mt352_reset[] = { 0x50, 0x80 }; 198c2ecf20Sopenharmony_ci static u8 mt352_mclk_ratio[] = { 0x8b, 0x00 }; 208c2ecf20Sopenharmony_ci static u8 mt352_adc_ctl_1_cfg[] = { 0x8E, 0x40 }; 218c2ecf20Sopenharmony_ci static u8 mt352_agc_cfg[] = { 0x67, 0x10, 0xa0 }; 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci static u8 mt352_sec_agc_cfg1[] = { 0x6a, 0xff }; 248c2ecf20Sopenharmony_ci static u8 mt352_sec_agc_cfg2[] = { 0x6d, 0xff }; 258c2ecf20Sopenharmony_ci static u8 mt352_sec_agc_cfg3[] = { 0x70, 0x40 }; 268c2ecf20Sopenharmony_ci static u8 mt352_sec_agc_cfg4[] = { 0x7b, 0x03 }; 278c2ecf20Sopenharmony_ci static u8 mt352_sec_agc_cfg5[] = { 0x7d, 0x0f }; 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci static u8 mt352_acq_ctl[] = { 0x53, 0x50 }; 308c2ecf20Sopenharmony_ci static u8 mt352_input_freq_1[] = { 0x56, 0x31, 0x06 }; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config)); 338c2ecf20Sopenharmony_ci udelay(2000); 348c2ecf20Sopenharmony_ci mt352_write(fe, mt352_reset, sizeof(mt352_reset)); 358c2ecf20Sopenharmony_ci mt352_write(fe, mt352_mclk_ratio, sizeof(mt352_mclk_ratio)); 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg)); 388c2ecf20Sopenharmony_ci mt352_write(fe, mt352_agc_cfg, sizeof(mt352_agc_cfg)); 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci mt352_write(fe, mt352_sec_agc_cfg1, sizeof(mt352_sec_agc_cfg1)); 418c2ecf20Sopenharmony_ci mt352_write(fe, mt352_sec_agc_cfg2, sizeof(mt352_sec_agc_cfg2)); 428c2ecf20Sopenharmony_ci mt352_write(fe, mt352_sec_agc_cfg3, sizeof(mt352_sec_agc_cfg3)); 438c2ecf20Sopenharmony_ci mt352_write(fe, mt352_sec_agc_cfg4, sizeof(mt352_sec_agc_cfg4)); 448c2ecf20Sopenharmony_ci mt352_write(fe, mt352_sec_agc_cfg5, sizeof(mt352_sec_agc_cfg5)); 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci mt352_write(fe, mt352_acq_ctl, sizeof(mt352_acq_ctl)); 478c2ecf20Sopenharmony_ci mt352_write(fe, mt352_input_freq_1, sizeof(mt352_input_freq_1)); 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci return 0; 508c2ecf20Sopenharmony_ci} 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistatic int umt_mt352_frontend_attach(struct dvb_usb_adapter *adap) 538c2ecf20Sopenharmony_ci{ 548c2ecf20Sopenharmony_ci struct mt352_config umt_config; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci memset(&umt_config,0,sizeof(struct mt352_config)); 578c2ecf20Sopenharmony_ci umt_config.demod_init = umt_mt352_demod_init; 588c2ecf20Sopenharmony_ci umt_config.demod_address = 0xf; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci adap->fe_adap[0].fe = dvb_attach(mt352_attach, &umt_config, &adap->dev->i2c_adap); 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci return 0; 638c2ecf20Sopenharmony_ci} 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_cistatic int umt_tuner_attach (struct dvb_usb_adapter *adap) 668c2ecf20Sopenharmony_ci{ 678c2ecf20Sopenharmony_ci dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x61, NULL, DVB_PLL_TUA6034); 688c2ecf20Sopenharmony_ci return 0; 698c2ecf20Sopenharmony_ci} 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci/* USB Driver stuff */ 728c2ecf20Sopenharmony_cistatic struct dvb_usb_device_properties umt_properties; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_cistatic int umt_probe(struct usb_interface *intf, 758c2ecf20Sopenharmony_ci const struct usb_device_id *id) 768c2ecf20Sopenharmony_ci{ 778c2ecf20Sopenharmony_ci if (0 == dvb_usb_device_init(intf, &umt_properties, 788c2ecf20Sopenharmony_ci THIS_MODULE, NULL, adapter_nr)) 798c2ecf20Sopenharmony_ci return 0; 808c2ecf20Sopenharmony_ci return -EINVAL; 818c2ecf20Sopenharmony_ci} 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci/* do not change the order of the ID table */ 848c2ecf20Sopenharmony_cistatic struct usb_device_id umt_table [] = { 858c2ecf20Sopenharmony_ci/* 00 */ { USB_DEVICE(USB_VID_HANFTEK, USB_PID_HANFTEK_UMT_010_COLD) }, 868c2ecf20Sopenharmony_ci/* 01 */ { USB_DEVICE(USB_VID_HANFTEK, USB_PID_HANFTEK_UMT_010_WARM) }, 878c2ecf20Sopenharmony_ci { } /* Terminating entry */ 888c2ecf20Sopenharmony_ci}; 898c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE (usb, umt_table); 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cistatic struct dvb_usb_device_properties umt_properties = { 928c2ecf20Sopenharmony_ci .caps = DVB_USB_IS_AN_I2C_ADAPTER, 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci .usb_ctrl = CYPRESS_FX2, 958c2ecf20Sopenharmony_ci .firmware = "dvb-usb-umt-010-02.fw", 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci .num_adapters = 1, 988c2ecf20Sopenharmony_ci .adapter = { 998c2ecf20Sopenharmony_ci { 1008c2ecf20Sopenharmony_ci .num_frontends = 1, 1018c2ecf20Sopenharmony_ci .fe = {{ 1028c2ecf20Sopenharmony_ci .streaming_ctrl = dibusb2_0_streaming_ctrl, 1038c2ecf20Sopenharmony_ci .frontend_attach = umt_mt352_frontend_attach, 1048c2ecf20Sopenharmony_ci .tuner_attach = umt_tuner_attach, 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci /* parameter for the MPEG2-data transfer */ 1078c2ecf20Sopenharmony_ci .stream = { 1088c2ecf20Sopenharmony_ci .type = USB_BULK, 1098c2ecf20Sopenharmony_ci .count = MAX_NO_URBS_FOR_DATA_STREAM, 1108c2ecf20Sopenharmony_ci .endpoint = 0x06, 1118c2ecf20Sopenharmony_ci .u = { 1128c2ecf20Sopenharmony_ci .bulk = { 1138c2ecf20Sopenharmony_ci .buffersize = 512, 1148c2ecf20Sopenharmony_ci } 1158c2ecf20Sopenharmony_ci } 1168c2ecf20Sopenharmony_ci }, 1178c2ecf20Sopenharmony_ci }}, 1188c2ecf20Sopenharmony_ci .size_of_priv = sizeof(struct dibusb_state), 1198c2ecf20Sopenharmony_ci } 1208c2ecf20Sopenharmony_ci }, 1218c2ecf20Sopenharmony_ci .power_ctrl = dibusb_power_ctrl, 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci .i2c_algo = &dibusb_i2c_algo, 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci .generic_bulk_ctrl_endpoint = 0x01, 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci .num_device_descs = 1, 1288c2ecf20Sopenharmony_ci .devices = { 1298c2ecf20Sopenharmony_ci { "Hanftek UMT-010 DVB-T USB2.0", 1308c2ecf20Sopenharmony_ci { &umt_table[0], NULL }, 1318c2ecf20Sopenharmony_ci { &umt_table[1], NULL }, 1328c2ecf20Sopenharmony_ci }, 1338c2ecf20Sopenharmony_ci } 1348c2ecf20Sopenharmony_ci}; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_cistatic struct usb_driver umt_driver = { 1378c2ecf20Sopenharmony_ci .name = "dvb_usb_umt_010", 1388c2ecf20Sopenharmony_ci .probe = umt_probe, 1398c2ecf20Sopenharmony_ci .disconnect = dvb_usb_device_exit, 1408c2ecf20Sopenharmony_ci .id_table = umt_table, 1418c2ecf20Sopenharmony_ci}; 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_cimodule_usb_driver(umt_driver); 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ciMODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@posteo.de>"); 1468c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Driver for HanfTek UMT 010 USB2.0 DVB-T device"); 1478c2ecf20Sopenharmony_ciMODULE_VERSION("1.0"); 1488c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 149