au6610.c 5.1 KB
Newer Older
1 2
/*
 * DVB USB Linux driver for Alcor Micro AU6610 DVB-T USB2.0.
3
 *
4
 * Copyright (C) 2006 Antti Palosaari <crope@iki.fi>
5
 *
6 7 8 9
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
10
 *
11 12 13 14 15 16 17 18
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 20 21 22 23 24
 */

#include "au6610.h"
#include "zl10353.h"
#include "qt1010.h"

25 26
DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);

27 28 29 30 31
static int au6610_usb_msg(struct dvb_usb_device *d, u8 operation, u8 addr,
			  u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
{
	int ret;
	u16 index;
32 33 34 35 36 37 38 39 40 41
	u8 *usb_buf;

	/*
	 * allocate enough for all known requests,
	 * read returns 5 and write 6 bytes
	 */
	usb_buf = kmalloc(6, GFP_KERNEL);
	if (!usb_buf)
		return -ENOMEM;

42 43 44 45 46 47 48 49 50
	switch (wlen) {
	case 1:
		index = wbuf[0] << 8;
		break;
	case 2:
		index = wbuf[0] << 8;
		index += wbuf[1];
		break;
	default:
51
		pr_err("%s: wlen = %d, aborting\n", KBUILD_MODNAME, wlen);
52 53
		ret = -EINVAL;
		goto error;
54 55 56
	}

	ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), operation,
57
			      USB_TYPE_VENDOR|USB_DIR_IN, addr << 1, index,
58
			      usb_buf, 6, AU6610_USB_TIMEOUT);
59
	if (ret < 0)
60
		goto error;
61 62 63 64 65 66 67

	switch (operation) {
	case AU6610_REQ_I2C_READ:
	case AU6610_REQ_USB_READ:
		/* requested value is always 5th byte in buffer */
		rbuf[0] = usb_buf[4];
	}
68 69
error:
	kfree(usb_buf);
70 71 72
	return ret;
}

73 74
static int au6610_i2c_msg(struct dvb_usb_device *d, u8 addr,
			  u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
{
	u8 request;
	u8 wo = (rbuf == NULL || rlen == 0); /* write-only */

	if (wo) {
		request = AU6610_REQ_I2C_WRITE;
	} else { /* rw */
		request = AU6610_REQ_I2C_READ;
	}

	return au6610_usb_msg(d, request, addr, wbuf, wlen, rbuf, rlen);
}


/* I2C */
90 91
static int au6610_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
			   int num)
92 93 94 95 96 97 98
{
	struct dvb_usb_device *d = i2c_get_adapdata(adap);
	int i;

	if (num > 2)
		return -EINVAL;

99 100 101
	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
		return -EAGAIN;

102 103 104 105
	for (i = 0; i < num; i++) {
		/* write/read request */
		if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
			if (au6610_i2c_msg(d, msg[i].addr, msg[i].buf,
106 107
					   msg[i].len, msg[i+1].buf,
					   msg[i+1].len) < 0)
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
				break;
			i++;
		} else if (au6610_i2c_msg(d, msg[i].addr, msg[i].buf,
					       msg[i].len, NULL, 0) < 0)
				break;
	}

	mutex_unlock(&d->i2c_mutex);
	return i;
}


static u32 au6610_i2c_func(struct i2c_adapter *adapter)
{
	return I2C_FUNC_I2C;
}

static struct i2c_algorithm au6610_i2c_algo = {
	.master_xfer   = au6610_i2c_xfer,
	.functionality = au6610_i2c_func,
};

/* Callbacks for DVB USB */
static struct zl10353_config au6610_zl10353_config = {
132
	.demod_address = 0x0f,
133 134 135 136 137 138
	.no_tuner = 1,
	.parallel_ts = 1,
};

static int au6610_zl10353_frontend_attach(struct dvb_usb_adapter *adap)
{
139
	adap->fe[0] = dvb_attach(zl10353_attach, &au6610_zl10353_config,
140
		&adap->dev->i2c_adap);
141
	if (adap->fe[0] == NULL)
142
		return -ENODEV;
143

144
	return 0;
145 146
}

147
static struct qt1010_config au6610_qt1010_config = {
148
	.i2c_address = 0x62
149 150 151 152 153
};

static int au6610_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
{
	return dvb_attach(qt1010_attach,
154
			  adap->fe[0], &adap->dev->i2c_adap,
155 156 157
			  &au6610_qt1010_config) == NULL ? -ENODEV : 0;
}

158
static int au6610_init(struct dvb_usb_device *d)
159
{
160 161 162
	/* TODO: this functionality belongs likely to the streaming control */
	/* bInterfaceNumber 0, bAlternateSetting 5 */
	return usb_set_interface(d->udev, 0, 5);
163 164
}

165 166 167 168
static struct dvb_usb_device_properties au6610_props = {
	.driver_name = KBUILD_MODNAME,
	.owner = THIS_MODULE,
	.adapter_nr = adapter_nr,
169

170 171 172 173
	.i2c_algo = &au6610_i2c_algo,
	.frontend_attach = au6610_zl10353_frontend_attach,
	.tuner_attach = au6610_qt1010_tuner_attach,
	.init = au6610_init,
174

175 176 177 178 179 180 181 182 183 184
	.num_adapters = 1,
	.adapter = {
		{
			.stream = {
				.type = USB_ISOC,
				.count = 5,
				.endpoint = 0x82,
				.u = {
					.isoc = {
						.framesperurb = 40,
185
						.framesize = 942,
186
						.interval = 1,
187 188 189
					}
				}
			},
190
		},
191
	},
192
};
193

194 195 196 197
static const struct usb_device_id au6610_id_table[] = {
	{ DVB_USB_DEVICE(USB_VID_ALCOR_MICRO, USB_PID_SIGMATEK_DVB_110,
		&au6610_props, "Sigmatek DVB-110", NULL) },
	{ }
198
};
199
MODULE_DEVICE_TABLE(usb, au6610_id_table);
200 201

static struct usb_driver au6610_driver = {
202 203 204 205 206 207 208 209
	.name = KBUILD_MODNAME,
	.id_table = au6610_id_table,
	.probe = dvb_usbv2_probe,
	.disconnect = dvb_usbv2_disconnect,
	.suspend = dvb_usbv2_suspend,
	.resume = dvb_usbv2_resume,
	.no_dynamic_id = 1,
	.soft_unbind = 1,
210 211
};

212
module_usb_driver(au6610_driver);
213 214

MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
215
MODULE_DESCRIPTION("Driver for Alcor Micro AU6610 DVB-T USB2.0");
216 217
MODULE_VERSION("0.1");
MODULE_LICENSE("GPL");