/* DVB USB framework compliant Linux driver for the AVerMedia AverTV DVB-T
 * USB2.0 (A800) DVB-T receiver.
 *
 * Copyright (C) 2005 Patrick Boettcher (patrick.boettcher@desy.de)
 *
 * Thanks to
 *   - AVerMedia who kindly provided information and
 *   - Glen Harris who suffered from my mistakes during development.
 *
 *	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, version 2.
 *
 * see Documentation/dvb/README.dvb-usb for more information
 */
#include "dibusb.h"

static int debug;
module_param(debug, int, 0644);
MODULE_PARM_DESC(debug, "set debugging level (rc=1 (or-able))." DVB_USB_DEBUG_STATUS);

DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);

#define deb_rc(args...)   dprintk(debug,0x01,args)

static int a800_power_ctrl(struct dvb_usb_device *d, int onoff)
{
	/* do nothing for the AVerMedia */
	return 0;
}

/* assure to put cold to 0 for iManufacturer == 1 */
static int a800_identify_state(struct usb_device *udev, struct dvb_usb_device_properties *props,
	struct dvb_usb_device_description **desc, int *cold)
{
	*cold = udev->descriptor.iManufacturer != 1;
	return 0;
}

static struct ir_scancode ir_codes_a800_table[] = {
	{ 0x0201, KEY_PROG1 },       /* SOURCE */
	{ 0x0200, KEY_POWER },       /* POWER */
	{ 0x0205, KEY_1 },           /* 1 */
	{ 0x0206, KEY_2 },           /* 2 */
	{ 0x0207, KEY_3 },           /* 3 */
	{ 0x0209, KEY_4 },           /* 4 */
	{ 0x020a, KEY_5 },           /* 5 */
	{ 0x020b, KEY_6 },           /* 6 */
	{ 0x020d, KEY_7 },           /* 7 */
	{ 0x020e, KEY_8 },           /* 8 */
	{ 0x020f, KEY_9 },           /* 9 */
	{ 0x0212, KEY_LEFT },        /* L / DISPLAY */
	{ 0x0211, KEY_0 },           /* 0 */
	{ 0x0213, KEY_RIGHT },       /* R / CH RTN */
	{ 0x0217, KEY_PROG2 },       /* SNAP SHOT */
	{ 0x0210, KEY_PROG3 },       /* 16-CH PREV */
	{ 0x021e, KEY_VOLUMEDOWN },  /* VOL DOWN */
	{ 0x020c, KEY_ZOOM },        /* FULL SCREEN */
	{ 0x021f, KEY_VOLUMEUP },    /* VOL UP */
	{ 0x0214, KEY_MUTE },        /* MUTE */
	{ 0x0208, KEY_AUDIO },       /* AUDIO */
	{ 0x0219, KEY_RECORD },      /* RECORD */
	{ 0x0218, KEY_PLAY },        /* PLAY */
	{ 0x021b, KEY_STOP },        /* STOP */
	{ 0x021a, KEY_PLAYPAUSE },   /* TIMESHIFT / PAUSE */
	{ 0x021d, KEY_BACK },        /* << / RED */
	{ 0x021c, KEY_FORWARD },     /* >> / YELLOW */
	{ 0x0203, KEY_TEXT },        /* TELETEXT */
	{ 0x0204, KEY_EPG },         /* EPG */
	{ 0x0215, KEY_MENU },        /* MENU */

	{ 0x0303, KEY_CHANNELUP },   /* CH UP */
	{ 0x0302, KEY_CHANNELDOWN }, /* CH DOWN */
	{ 0x0301, KEY_FIRST },       /* |<< / GREEN */
	{ 0x0300, KEY_LAST },        /* >>| / BLUE */

};

static int a800_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
{
	u8 key[5];
	if (usb_control_msg(d->udev,usb_rcvctrlpipe(d->udev,0),
				0x04, USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, key, 5,
				2000) != 5)
		return -ENODEV;

	/* call the universal NEC remote processor, to find out the key's state and event */
	dvb_usb_nec_rc_key_to_event(d,key,event,state);
	if (key[0] != 0)
		deb_rc("key: %x %x %x %x %x\n",key[0],key[1],key[2],key[3],key[4]);
	return 0;
}

/* USB Driver stuff */
static struct dvb_usb_device_properties a800_properties;

static int a800_probe(struct usb_interface *intf,
		const struct usb_device_id *id)
{
	return dvb_usb_device_init(intf, &a800_properties,
				   THIS_MODULE, NULL, adapter_nr);
}

/* do not change the order of the ID table */
static struct usb_device_id a800_table [] = {
/* 00 */	{ USB_DEVICE(USB_VID_AVERMEDIA,     USB_PID_AVERMEDIA_DVBT_USB2_COLD) },
/* 01 */	{ USB_DEVICE(USB_VID_AVERMEDIA,     USB_PID_AVERMEDIA_DVBT_USB2_WARM) },
			{ }		/* Terminating entry */
};
MODULE_DEVICE_TABLE (usb, a800_table);

static struct dvb_usb_device_properties a800_properties = {
	.caps = DVB_USB_IS_AN_I2C_ADAPTER,

	.usb_ctrl = CYPRESS_FX2,
	.firmware = "dvb-usb-avertv-a800-02.fw",

	.num_adapters = 1,
	.adapter = {
		{
			.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
			.pid_filter_count = 32,
			.streaming_ctrl   = dibusb2_0_streaming_ctrl,
			.pid_filter       = dibusb_pid_filter,
			.pid_filter_ctrl  = dibusb_pid_filter_ctrl,

			.frontend_attach  = dibusb_dib3000mc_frontend_attach,
			.tuner_attach     = dibusb_dib3000mc_tuner_attach,

			/* parameter for the MPEG2-data transfer */
					.stream = {
						.type = USB_BULK,
				.count = 7,
				.endpoint = 0x06,
				.u = {
					.bulk = {
						.buffersize = 4096,
					}
				}
			},

			.size_of_priv     = sizeof(struct dibusb_state),
		},
	},

	.power_ctrl       = a800_power_ctrl,
	.identify_state   = a800_identify_state,

	.rc.legacy = {
		.rc_interval      = DEFAULT_RC_INTERVAL,
		.rc_key_map       = ir_codes_a800_table,
		.rc_key_map_size  = ARRAY_SIZE(ir_codes_a800_table),
		.rc_query         = a800_rc_query,
	},

	.i2c_algo         = &dibusb_i2c_algo,

	.generic_bulk_ctrl_endpoint = 0x01,
	.num_device_descs = 1,
	.devices = {
		{   "AVerMedia AverTV DVB-T USB 2.0 (A800)",
			{ &a800_table[0], NULL },
			{ &a800_table[1], NULL },
		},
	}
};

static struct usb_driver a800_driver = {
	.name		= "dvb_usb_a800",
	.probe		= a800_probe,
	.disconnect = dvb_usb_device_exit,
	.id_table	= a800_table,
};

/* module stuff */
static int __init a800_module_init(void)
{
	int result;
	if ((result = usb_register(&a800_driver))) {
		err("usb_register failed. Error number %d",result);
		return result;
	}

	return 0;
}

static void __exit a800_module_exit(void)
{
	/* deregister this driver from the USB subsystem */
	usb_deregister(&a800_driver);
}

module_init (a800_module_init);
module_exit (a800_module_exit);

MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
MODULE_DESCRIPTION("AVerMedia AverTV DVB-T USB 2.0 (A800)");
MODULE_VERSION("1.0");
MODULE_LICENSE("GPL");
