Path: blob/master/drivers/media/dvb/dvb-usb/digitv.c
15111 views
/* DVB USB compliant linux driver for Nebula Electronics uDigiTV DVB-T USB2.01* receiver2*3* Copyright (C) 2005 Patrick Boettcher ([email protected])4*5* partly based on the SDK published by Nebula Electronics6*7* This program is free software; you can redistribute it and/or modify it8* under the terms of the GNU General Public License as published by the Free9* Software Foundation, version 2.10*11* see Documentation/dvb/README.dvb-usb for more information12*/13#include "digitv.h"1415#include "mt352.h"16#include "nxt6000.h"1718/* debug */19static int dvb_usb_digitv_debug;20module_param_named(debug,dvb_usb_digitv_debug, int, 0644);21MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);2223DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);2425#define deb_rc(args...) dprintk(dvb_usb_digitv_debug,0x01,args)2627static int digitv_ctrl_msg(struct dvb_usb_device *d,28u8 cmd, u8 vv, u8 *wbuf, int wlen, u8 *rbuf, int rlen)29{30int wo = (rbuf == NULL || rlen == 0); /* write-only */31u8 sndbuf[7],rcvbuf[7];32memset(sndbuf,0,7); memset(rcvbuf,0,7);3334sndbuf[0] = cmd;35sndbuf[1] = vv;36sndbuf[2] = wo ? wlen : rlen;3738if (wo) {39memcpy(&sndbuf[3],wbuf,wlen);40dvb_usb_generic_write(d,sndbuf,7);41} else {42dvb_usb_generic_rw(d,sndbuf,7,rcvbuf,7,10);43memcpy(rbuf,&rcvbuf[3],rlen);44}45return 0;46}4748/* I2C */49static int digitv_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)50{51struct dvb_usb_device *d = i2c_get_adapdata(adap);52int i;5354if (mutex_lock_interruptible(&d->i2c_mutex) < 0)55return -EAGAIN;5657if (num > 2)58warn("more than 2 i2c messages at a time is not handled yet. TODO.");5960for (i = 0; i < num; i++) {61/* write/read request */62if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {63if (digitv_ctrl_msg(d, USB_READ_COFDM, msg[i].buf[0], NULL, 0,64msg[i+1].buf,msg[i+1].len) < 0)65break;66i++;67} else68if (digitv_ctrl_msg(d,USB_WRITE_COFDM, msg[i].buf[0],69&msg[i].buf[1],msg[i].len-1,NULL,0) < 0)70break;71}7273mutex_unlock(&d->i2c_mutex);74return i;75}7677static u32 digitv_i2c_func(struct i2c_adapter *adapter)78{79return I2C_FUNC_I2C;80}8182static struct i2c_algorithm digitv_i2c_algo = {83.master_xfer = digitv_i2c_xfer,84.functionality = digitv_i2c_func,85};8687/* Callbacks for DVB USB */88static int digitv_identify_state (struct usb_device *udev, struct89dvb_usb_device_properties *props, struct dvb_usb_device_description **desc,90int *cold)91{92*cold = udev->descriptor.iManufacturer == 0 && udev->descriptor.iProduct == 0;93return 0;94}9596static int digitv_mt352_demod_init(struct dvb_frontend *fe)97{98static u8 reset_buf[] = { 0x89, 0x38, 0x8a, 0x2d, 0x50, 0x80 };99static u8 init_buf[] = { 0x68, 0xa0, 0x8e, 0x40, 0x53, 0x50,1000x67, 0x20, 0x7d, 0x01, 0x7c, 0x00, 0x7a, 0x00,1010x79, 0x20, 0x57, 0x05, 0x56, 0x31, 0x88, 0x0f,1020x75, 0x32 };103int i;104105for (i = 0; i < ARRAY_SIZE(reset_buf); i += 2)106mt352_write(fe, &reset_buf[i], 2);107108msleep(1);109110for (i = 0; i < ARRAY_SIZE(init_buf); i += 2)111mt352_write(fe, &init_buf[i], 2);112113return 0;114}115116static struct mt352_config digitv_mt352_config = {117.demod_init = digitv_mt352_demod_init,118};119120static int digitv_nxt6000_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *fep)121{122struct dvb_usb_adapter *adap = fe->dvb->priv;123u8 b[5];124125fe->ops.tuner_ops.calc_regs(fe, fep, b, sizeof(b));126if (fe->ops.i2c_gate_ctrl)127fe->ops.i2c_gate_ctrl(fe, 1);128return digitv_ctrl_msg(adap->dev, USB_WRITE_TUNER, 0, &b[1], 4, NULL, 0);129}130131static struct nxt6000_config digitv_nxt6000_config = {132.clock_inversion = 1,133};134135static int digitv_frontend_attach(struct dvb_usb_adapter *adap)136{137struct digitv_state *st = adap->dev->priv;138139if ((adap->fe = dvb_attach(mt352_attach, &digitv_mt352_config, &adap->dev->i2c_adap)) != NULL) {140st->is_nxt6000 = 0;141return 0;142}143if ((adap->fe = dvb_attach(nxt6000_attach, &digitv_nxt6000_config, &adap->dev->i2c_adap)) != NULL) {144st->is_nxt6000 = 1;145return 0;146}147return -EIO;148}149150static int digitv_tuner_attach(struct dvb_usb_adapter *adap)151{152struct digitv_state *st = adap->dev->priv;153154if (!dvb_attach(dvb_pll_attach, adap->fe, 0x60, NULL, DVB_PLL_TDED4))155return -ENODEV;156157if (st->is_nxt6000)158adap->fe->ops.tuner_ops.set_params = digitv_nxt6000_tuner_set_params;159160return 0;161}162163static struct rc_map_table rc_map_digitv_table[] = {164{ 0x5f55, KEY_0 },165{ 0x6f55, KEY_1 },166{ 0x9f55, KEY_2 },167{ 0xaf55, KEY_3 },168{ 0x5f56, KEY_4 },169{ 0x6f56, KEY_5 },170{ 0x9f56, KEY_6 },171{ 0xaf56, KEY_7 },172{ 0x5f59, KEY_8 },173{ 0x6f59, KEY_9 },174{ 0x9f59, KEY_TV },175{ 0xaf59, KEY_AUX },176{ 0x5f5a, KEY_DVD },177{ 0x6f5a, KEY_POWER },178{ 0x9f5a, KEY_CAMERA }, /* labelled 'Picture' */179{ 0xaf5a, KEY_AUDIO },180{ 0x5f65, KEY_INFO },181{ 0x6f65, KEY_F13 }, /* 16:9 */182{ 0x9f65, KEY_F14 }, /* 14:9 */183{ 0xaf65, KEY_EPG },184{ 0x5f66, KEY_EXIT },185{ 0x6f66, KEY_MENU },186{ 0x9f66, KEY_UP },187{ 0xaf66, KEY_DOWN },188{ 0x5f69, KEY_LEFT },189{ 0x6f69, KEY_RIGHT },190{ 0x9f69, KEY_ENTER },191{ 0xaf69, KEY_CHANNELUP },192{ 0x5f6a, KEY_CHANNELDOWN },193{ 0x6f6a, KEY_VOLUMEUP },194{ 0x9f6a, KEY_VOLUMEDOWN },195{ 0xaf6a, KEY_RED },196{ 0x5f95, KEY_GREEN },197{ 0x6f95, KEY_YELLOW },198{ 0x9f95, KEY_BLUE },199{ 0xaf95, KEY_SUBTITLE },200{ 0x5f96, KEY_F15 }, /* AD */201{ 0x6f96, KEY_TEXT },202{ 0x9f96, KEY_MUTE },203{ 0xaf96, KEY_REWIND },204{ 0x5f99, KEY_STOP },205{ 0x6f99, KEY_PLAY },206{ 0x9f99, KEY_FASTFORWARD },207{ 0xaf99, KEY_F16 }, /* chapter */208{ 0x5f9a, KEY_PAUSE },209{ 0x6f9a, KEY_PLAY },210{ 0x9f9a, KEY_RECORD },211{ 0xaf9a, KEY_F17 }, /* picture in picture */212{ 0x5fa5, KEY_KPPLUS }, /* zoom in */213{ 0x6fa5, KEY_KPMINUS }, /* zoom out */214{ 0x9fa5, KEY_F18 }, /* capture */215{ 0xafa5, KEY_F19 }, /* web */216{ 0x5fa6, KEY_EMAIL },217{ 0x6fa6, KEY_PHONE },218{ 0x9fa6, KEY_PC },219};220221static int digitv_rc_query(struct dvb_usb_device *d, u32 *event, int *state)222{223int i;224u8 key[5];225u8 b[4] = { 0 };226227*event = 0;228*state = REMOTE_NO_KEY_PRESSED;229230digitv_ctrl_msg(d,USB_READ_REMOTE,0,NULL,0,&key[1],4);231232/* Tell the device we've read the remote. Not sure how necessary233this is, but the Nebula SDK does it. */234digitv_ctrl_msg(d,USB_WRITE_REMOTE,0,b,4,NULL,0);235236/* if something is inside the buffer, simulate key press */237if (key[1] != 0)238{239for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) {240if (rc5_custom(&d->props.rc.legacy.rc_map_table[i]) == key[1] &&241rc5_data(&d->props.rc.legacy.rc_map_table[i]) == key[2]) {242*event = d->props.rc.legacy.rc_map_table[i].keycode;243*state = REMOTE_KEY_PRESSED;244return 0;245}246}247}248249if (key[0] != 0)250deb_rc("key: %x %x %x %x %x\n",key[0],key[1],key[2],key[3],key[4]);251return 0;252}253254/* DVB USB Driver stuff */255static struct dvb_usb_device_properties digitv_properties;256257static int digitv_probe(struct usb_interface *intf,258const struct usb_device_id *id)259{260struct dvb_usb_device *d;261int ret = dvb_usb_device_init(intf, &digitv_properties, THIS_MODULE, &d,262adapter_nr);263if (ret == 0) {264u8 b[4] = { 0 };265266if (d != NULL) { /* do that only when the firmware is loaded */267b[0] = 1;268digitv_ctrl_msg(d,USB_WRITE_REMOTE_TYPE,0,b,4,NULL,0);269270b[0] = 0;271digitv_ctrl_msg(d,USB_WRITE_REMOTE,0,b,4,NULL,0);272}273}274return ret;275}276277static struct usb_device_id digitv_table [] = {278{ USB_DEVICE(USB_VID_ANCHOR, USB_PID_NEBULA_DIGITV) },279{ } /* Terminating entry */280};281MODULE_DEVICE_TABLE (usb, digitv_table);282283static struct dvb_usb_device_properties digitv_properties = {284.caps = DVB_USB_IS_AN_I2C_ADAPTER,285286.usb_ctrl = CYPRESS_FX2,287.firmware = "dvb-usb-digitv-02.fw",288289.size_of_priv = sizeof(struct digitv_state),290291.num_adapters = 1,292.adapter = {293{294.frontend_attach = digitv_frontend_attach,295.tuner_attach = digitv_tuner_attach,296297/* parameter for the MPEG2-data transfer */298.stream = {299.type = USB_BULK,300.count = 7,301.endpoint = 0x02,302.u = {303.bulk = {304.buffersize = 4096,305}306}307},308}309},310.identify_state = digitv_identify_state,311312.rc.legacy = {313.rc_interval = 1000,314.rc_map_table = rc_map_digitv_table,315.rc_map_size = ARRAY_SIZE(rc_map_digitv_table),316.rc_query = digitv_rc_query,317},318319.i2c_algo = &digitv_i2c_algo,320321.generic_bulk_ctrl_endpoint = 0x01,322323.num_device_descs = 1,324.devices = {325{ "Nebula Electronics uDigiTV DVB-T USB2.0)",326{ &digitv_table[0], NULL },327{ NULL },328},329{ NULL },330}331};332333static struct usb_driver digitv_driver = {334.name = "dvb_usb_digitv",335.probe = digitv_probe,336.disconnect = dvb_usb_device_exit,337.id_table = digitv_table,338};339340/* module stuff */341static int __init digitv_module_init(void)342{343int result;344if ((result = usb_register(&digitv_driver))) {345err("usb_register failed. Error number %d",result);346return result;347}348349return 0;350}351352static void __exit digitv_module_exit(void)353{354/* deregister this driver from the USB subsystem */355usb_deregister(&digitv_driver);356}357358module_init (digitv_module_init);359module_exit (digitv_module_exit);360361MODULE_AUTHOR("Patrick Boettcher <[email protected]>");362MODULE_DESCRIPTION("Driver for Nebula Electronics uDigiTV DVB-T USB2.0");363MODULE_VERSION("1.0-alpha");364MODULE_LICENSE("GPL");365366367