summaryrefslogtreecommitdiffstats
path: root/src/af903x-core.c
blob: 0829a8e2deeb6f5615bced729507110255d03b64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "af903x.h"

DEVICE_CONTEXT DC;
bool TunerInited0, TunerInited1, DeviceReboot;
DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);

static int af903x_probe(struct usb_interface *intf,
		const struct usb_device_id *id)
{
	int retval = -ENOMEM;
	int i;

	printk("===af903x usb device pluged in!! ===\n");
	retval = Device_init(interface_to_usbdev(intf),&DC, true);
	if (retval){
                printk("Device_init Fail: 0x%08x\n", retval);
		return retval;
        }

	if ( af903x_device_count > 2)
		af903x_device_count = 2;
	
	for (i = 0; i < af903x_device_count; i++)
	{
	    if (DC.architecture == Architecture_PIP)
		af903x_properties[i].num_adapters = 2;
	    if (dvb_usb_device_init(intf, &af903x_properties[i], THIS_MODULE, NULL,adapter_nr) == 0)
		{printk("dvb_usb_device_init success!!\n");return 0;}
	}

	return -ENOMEM;
}

static int af903x_suspend(struct usb_interface *intf, u32 state)
{
	int error;
	deb_data("Enter %s Function\n",__FUNCTION__);

    if (DevicePower)
    {
	error = DL_CheckTunerInited(0, (Bool *) &TunerInited0);
	error = DL_CheckTunerInited(1, (Bool *) &TunerInited1);

	error = DL_ApCtrl(0, 0);
	error = DL_ApCtrl(1, 0);
	if (error) {deb_data("DL_ApCtrl error : 0x%x\n", error);}

	DeviceReboot = true;
    }
	return 0;
}

static int af903x_resume(struct usb_interface *intf)
{
	int retval = -ENOMEM;
	int error;
	deb_data("Enter %s Function\n",__FUNCTION__);

    if(DeviceReboot == true)
    {
	retval = Device_init(interface_to_usbdev(intf),&DC, false);
        if (retval)
                if(retval) printk("Device_init Fail: 0x%08x\n", retval);

	if (TunerInited0)
	    error = DL_ApCtrl(0, 1);
	if (TunerInited1)
	    error = DL_ApCtrl(1, 1);
    }
        return 0;
}


static struct usb_driver af903x_driver = {
	.name       = "dvb_usb_af903x",
	.probe      = af903x_probe,
	.disconnect = dvb_usb_device_exit,
	.id_table   = af903x_usb_id_table,
	.suspend    = af903x_suspend,
	.resume     = af903x_resume,
};

static int __init af903x_module_init(void)
{
	int result;

	info("%s",__FUNCTION__);
	printk("dvb_usb_af903x Module is loaded \n");

	if ((result = usb_register(&af903x_driver))) {
		err("usb_register failed. Error number %d",result);
		return result;
	}
	return 0;
}

static void __exit af903x_module_exit(void)
{
	printk("dvb_usb_af903x Module is unloaded!\n");
	usb_deregister(&af903x_driver);
}

module_init (af903x_module_init);
module_exit (af903x_module_exit);

MODULE_AUTHOR("Jimmy Chen <JyunYu.Chen@ite.com.tw>");
MODULE_DESCRIPTION("Driver for devices based on ITEtech AF903X");
MODULE_VERSION(DRIVER_RELEASE_VERSION);
MODULE_LICENSE("GPL");