File: ungrab-winmodem.c

package info (click to toggle)
sl-modem 2.9.11~20110321-11
  • links: PTS, VCS
  • area: non-free
  • in suites: jessie, jessie-kfreebsd
  • size: 3,448 kB
  • ctags: 2,972
  • sloc: ansic: 11,002; sh: 809; makefile: 232; python: 40; perl: 11
file content (105 lines) | stat: -rw-r--r-- 3,414 bytes parent folder | download | duplicates (4)
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
/*
 * Copyright (c) 2005, linmodems.org
 * 
 * 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.
 *
 * Sasha K (sashak@smlink.com)
 *
 * ungrab-winmodem.c - try to release softmodem device when grabbed by others.
 *
 
  *	20070505: -Renamed Motorola device 5600
  * http://archives.linmodems.org/26589
  * Marvin Stodolsky (marvin.stodolsky@gmail.com)
  * Alvaro Aguirre (alvaro.aguirre@gmail.com)
  */


#include <linux/version.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
#include <linux/config.h>
#endif
#include <linux/module.h>
#include <linux/init.h>
#include <linux/pci.h>
#include <linux/kernel.h>

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
#define pci_find_device pci_get_device
#endif

#define PCI_DEVICE_ID_ALI5457			0x5457
#define PCI_DEVICE_ID_ALI5459			0x5459
#define PCI_DEVICE_ID_ALI545A			0x545A

#define PCI_VENDOR_ID_SMARTLINK                 0x2000		
#define PCI_VENDOR_ID_SMARTLINK_1		0x163c
#define PCI_VENDOR_ID_SMARTLINK_2		0x10a5
#define PCI_VENDOR_ID_SMARTLINK_3		0x2003
#define PCI_DEVICE_ID_SL2800			0x2800
#define PCI_DEVICE_ID_SL1900			0x3052
#define PCI_DEVICE_ID_ND92XPA                   0x8800 /* ND92XPA */
#define PCI_VENDOR_ID_MOTOROLA                  0x1057 /* Motorola */
#define PCI_VENDOR_ID_SLI1543                   0x1543 /* Silicon Inst 1543:3052 sub 1543:3000 */


static struct pci_device_id softmodem_pci_tbl [] = {
	/* 1543:3052 */
	{PCI_VENDOR_ID_SLI1543, PCI_DEVICE_ID_SL1900, PCI_ANY_ID, PCI_ANY_ID },
	/* 1057:3052 */
	{PCI_VENDOR_ID_MOTOROLA, PCI_DEVICE_ID_SL1900, PCI_ANY_ID, PCI_ANY_ID },
	/* 163c:3052 */
	{PCI_VENDOR_ID_SMARTLINK_1, PCI_DEVICE_ID_SL1900, PCI_ANY_ID, PCI_ANY_ID },
	/* 10a5:3052 */
	{PCI_VENDOR_ID_SMARTLINK_2, PCI_DEVICE_ID_SL1900, PCI_ANY_ID, PCI_ANY_ID },
	/* 10b9:5459 */
	{PCI_VENDOR_ID_AL, PCI_DEVICE_ID_ALI5459, PCI_ANY_ID, PCI_ANY_ID },
	/* 10b9:5457 */
	{PCI_VENDOR_ID_AL, PCI_DEVICE_ID_ALI5457, PCI_ANY_ID, PCI_ANY_ID },
	/* 10b9:545a */
	{PCI_VENDOR_ID_AL, PCI_DEVICE_ID_ALI545A, PCI_ANY_ID, PCI_ANY_ID },
	/* 2000:2800 */
	{PCI_VENDOR_ID_SMARTLINK, PCI_DEVICE_ID_SL2800, PCI_ANY_ID, PCI_ANY_ID },
	/* 2003:8800 */
	{PCI_VENDOR_ID_SMARTLINK_3, PCI_DEVICE_ID_ND92XPA, PCI_ANY_ID, PCI_ANY_ID },
	/* pctel HSP1688 */
	{ 0x134d, 0x2189, PCI_ANY_ID, PCI_ANY_ID },
	/* phillips pci modem */
	{ 0x1131, 0x3400, PCI_ANY_ID, PCI_ANY_ID },
	{0,}
};


#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
#define pci_match_id(tbl, dev) pci_match_device(tbl, dev)
#endif

static int __init softmodem_release_init(void)
{
	struct pci_dev *dev = NULL;
	struct device *reldev;
        while ((dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
		if(pci_match_id(softmodem_pci_tbl, dev) && pci_dev_driver(dev) &&
		   (reldev = get_device(&dev->dev)) ) {
			printk(KERN_INFO "device %04x:%04x is grabbed by driver %s: try to release\n",
				  dev->vendor, dev->device,
				  (reldev&&reldev->driver) ? reldev->driver->name : "unknown");
			device_release_driver(reldev);
			put_device(reldev);
		}
	}
	return 0;
}

static void __exit softmodem_release_exit(void)
{
}

module_init(softmodem_release_init);
module_exit(softmodem_release_exit);

MODULE_AUTHOR("linmodems.org");
MODULE_DESCRIPTION("No driver - just try release softmodem device");
MODULE_LICENSE("GPL");