Path: blob/master/drivers/media/dvb/dvb-usb/dtv5100.c
15112 views
/*1* DVB USB Linux driver for AME DTV-5100 USB2.0 DVB-T2*3* Copyright (C) 2008 Antoine Jacquet <[email protected]>4* http://royale.zerezo.com/dtv5100/5*6* Inspired by gl861.c and au6610.c drivers7*8* This program is free software; you can redistribute it and/or modify9* it under the terms of the GNU General Public License as published by10* the Free Software Foundation; either version 2 of the License, or11* (at your option) any later version.12*13* This program is distributed in the hope that it will be useful,14* but WITHOUT ANY WARRANTY; without even the implied warranty of15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the16* GNU General Public License for more details.17*18* You should have received a copy of the GNU General Public License19* along with this program; if not, write to the Free Software20* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA21*/2223#include "dtv5100.h"24#include "zl10353.h"25#include "qt1010.h"2627/* debug */28static int dvb_usb_dtv5100_debug;29module_param_named(debug, dvb_usb_dtv5100_debug, int, 0644);30MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);31DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);3233static int dtv5100_i2c_msg(struct dvb_usb_device *d, u8 addr,34u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)35{36u8 request;37u8 type;38u16 value;39u16 index;4041switch (wlen) {42case 1:43/* write { reg }, read { value } */44request = (addr == DTV5100_DEMOD_ADDR ? DTV5100_DEMOD_READ :45DTV5100_TUNER_READ);46type = USB_TYPE_VENDOR | USB_DIR_IN;47value = 0;48break;49case 2:50/* write { reg, value } */51request = (addr == DTV5100_DEMOD_ADDR ? DTV5100_DEMOD_WRITE :52DTV5100_TUNER_WRITE);53type = USB_TYPE_VENDOR | USB_DIR_OUT;54value = wbuf[1];55break;56default:57warn("wlen = %x, aborting.", wlen);58return -EINVAL;59}60index = (addr << 8) + wbuf[0];6162msleep(1); /* avoid I2C errors */63return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), request,64type, value, index, rbuf, rlen,65DTV5100_USB_TIMEOUT);66}6768/* I2C */69static int dtv5100_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],70int num)71{72struct dvb_usb_device *d = i2c_get_adapdata(adap);73int i;7475if (num > 2)76return -EINVAL;7778if (mutex_lock_interruptible(&d->i2c_mutex) < 0)79return -EAGAIN;8081for (i = 0; i < num; i++) {82/* write/read request */83if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {84if (dtv5100_i2c_msg(d, msg[i].addr, msg[i].buf,85msg[i].len, msg[i+1].buf,86msg[i+1].len) < 0)87break;88i++;89} else if (dtv5100_i2c_msg(d, msg[i].addr, msg[i].buf,90msg[i].len, NULL, 0) < 0)91break;92}9394mutex_unlock(&d->i2c_mutex);95return i;96}9798static u32 dtv5100_i2c_func(struct i2c_adapter *adapter)99{100return I2C_FUNC_I2C;101}102103static struct i2c_algorithm dtv5100_i2c_algo = {104.master_xfer = dtv5100_i2c_xfer,105.functionality = dtv5100_i2c_func,106};107108/* Callbacks for DVB USB */109static struct zl10353_config dtv5100_zl10353_config = {110.demod_address = DTV5100_DEMOD_ADDR,111.no_tuner = 1,112.parallel_ts = 1,113};114115static int dtv5100_frontend_attach(struct dvb_usb_adapter *adap)116{117adap->fe = dvb_attach(zl10353_attach, &dtv5100_zl10353_config,118&adap->dev->i2c_adap);119if (adap->fe == NULL)120return -EIO;121122/* disable i2c gate, or it won't work... is this safe? */123adap->fe->ops.i2c_gate_ctrl = NULL;124125return 0;126}127128static struct qt1010_config dtv5100_qt1010_config = {129.i2c_address = DTV5100_TUNER_ADDR130};131132static int dtv5100_tuner_attach(struct dvb_usb_adapter *adap)133{134return dvb_attach(qt1010_attach,135adap->fe, &adap->dev->i2c_adap,136&dtv5100_qt1010_config) == NULL ? -ENODEV : 0;137}138139/* DVB USB Driver stuff */140static struct dvb_usb_device_properties dtv5100_properties;141142static int dtv5100_probe(struct usb_interface *intf,143const struct usb_device_id *id)144{145int i, ret;146struct usb_device *udev = interface_to_usbdev(intf);147148/* initialize non qt1010/zl10353 part? */149for (i = 0; dtv5100_init[i].request; i++) {150ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),151dtv5100_init[i].request,152USB_TYPE_VENDOR | USB_DIR_OUT,153dtv5100_init[i].value,154dtv5100_init[i].index, NULL, 0,155DTV5100_USB_TIMEOUT);156if (ret)157return ret;158}159160ret = dvb_usb_device_init(intf, &dtv5100_properties,161THIS_MODULE, NULL, adapter_nr);162if (ret)163return ret;164165return 0;166}167168static struct usb_device_id dtv5100_table[] = {169{ USB_DEVICE(0x06be, 0xa232) },170{ } /* Terminating entry */171};172MODULE_DEVICE_TABLE(usb, dtv5100_table);173174static struct dvb_usb_device_properties dtv5100_properties = {175.caps = DVB_USB_IS_AN_I2C_ADAPTER,176.usb_ctrl = DEVICE_SPECIFIC,177178.size_of_priv = 0,179180.num_adapters = 1,181.adapter = {{182.frontend_attach = dtv5100_frontend_attach,183.tuner_attach = dtv5100_tuner_attach,184185.stream = {186.type = USB_BULK,187.count = 8,188.endpoint = 0x82,189.u = {190.bulk = {191.buffersize = 4096,192}193}194},195} },196197.i2c_algo = &dtv5100_i2c_algo,198199.num_device_descs = 1,200.devices = {201{202.name = "AME DTV-5100 USB2.0 DVB-T",203.cold_ids = { NULL },204.warm_ids = { &dtv5100_table[0], NULL },205},206}207};208209static struct usb_driver dtv5100_driver = {210.name = "dvb_usb_dtv5100",211.probe = dtv5100_probe,212.disconnect = dvb_usb_device_exit,213.id_table = dtv5100_table,214};215216/* module stuff */217static int __init dtv5100_module_init(void)218{219int ret;220221ret = usb_register(&dtv5100_driver);222if (ret)223err("usb_register failed. Error number %d", ret);224225return ret;226}227228static void __exit dtv5100_module_exit(void)229{230/* deregister this driver from the USB subsystem */231usb_deregister(&dtv5100_driver);232}233234module_init(dtv5100_module_init);235module_exit(dtv5100_module_exit);236237MODULE_AUTHOR(DRIVER_AUTHOR);238MODULE_DESCRIPTION(DRIVER_DESC);239MODULE_LICENSE("GPL");240241242