1 // ip2.c
2 // This is a dummy module to make the firmware available when needed
3 // and allows it to be unloaded when not. Rumor is the __initdata
4 // macro doesn't always works on all platforms so we use this kludge.
5 // If not compiled as a module it just makes fip_firm avaliable then
6 // __initdata should work as advertized
7 //
8
9 #include <linux/module.h>
10 #include <linux/version.h>
11 #include <linux/init.h>
12 #include <linux/wait.h>
13
14 #ifndef __init
15 #define __init
16 #endif
17 #ifndef __initfunc
18 #define __initfunc(a) a
19 #endif
20 #ifndef __initdata
21 #define __initdata
22 #endif
23
24 #include "./ip2/ip2types.h"
25 #include "./ip2/fip_firm.h" // the meat
26
27 int
28 ip2_loadmain(int *, int *, unsigned char *, int ); // ref into ip2main.c
29
30 /* Note: Add compiled in defaults to these arrays, not to the structure
31 in ip2/ip2.h any longer. That structure WILL get overridden
32 by these values, or command line values, or insmod values!!! =mhw=
33 */
34 static int io[IP2_MAX_BOARDS]= { 0, 0, 0, 0 };
35 static int irq[IP2_MAX_BOARDS] = { -1, -1, -1, -1 };
36
37 #ifdef MODULE
38
39 static int poll_only = 0;
40
41 # if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
42 MODULE_AUTHOR("Doug McNash");
43 MODULE_DESCRIPTION("Computone IntelliPort Plus Driver");
44 MODULE_PARM(irq,"1-"__MODULE_STRING(IP2_MAX_BOARDS) "i");
45 MODULE_PARM_DESC(irq,"Interrupts for IntelliPort Cards");
46 MODULE_PARM(io,"1-"__MODULE_STRING(IP2_MAX_BOARDS) "i");
47 MODULE_PARM_DESC(io,"I/O ports for IntelliPort Cards");
48 MODULE_PARM(poll_only,"1i");
49 MODULE_PARM_DESC(poll_only,"Do not use card interrupts");
50 # endif /* LINUX_VERSION */
51
52
53 //======================================================================
54 int
init_module(void)55 init_module(void)
56 {
57 int rc;
58
59 MOD_INC_USE_COUNT; // hold till done
60
61 if( poll_only ) {
62 /* Hard lock the interrupts to zero */
63 irq[0] = irq[1] = irq[2] = irq[3] = 0;
64 }
65
66 rc = ip2_loadmain(io,irq,(unsigned char *)fip_firm,sizeof(fip_firm));
67 // The call to lock and load main, create dep
68
69 MOD_DEC_USE_COUNT; //done - kerneld now can unload us
70 return rc;
71 }
72
73 //======================================================================
74 int
ip2_init(void)75 ip2_init(void)
76 {
77 // call to this is in tty_io.c so we need this
78 return 0;
79 }
80
81 //======================================================================
82 void
cleanup_module(void)83 cleanup_module(void)
84 {
85 }
86
87 MODULE_LICENSE("GPL");
88
89 #else // !MODULE
90
91 #ifndef NULL
92 # define NULL ((void *) 0)
93 #endif
94
95 /******************************************************************************
96 * ip2_setup:
97 * str: kernel command line string
98 *
99 * Can't autoprobe the boards so user must specify configuration on
100 * kernel command line. Sane people build it modular but the others
101 * come here.
102 *
103 * Alternating pairs of io,irq for up to 4 boards.
104 * ip2=io0,irq0,io1,irq1,io2,irq2,io3,irq3
105 *
106 * io=0 => No board
107 * io=1 => PCI
108 * io=2 => EISA
109 * else => ISA I/O address
110 *
111 * irq=0 or invalid for ISA will revert to polling mode
112 *
113 * Any value = -1, do not overwrite compiled in value.
114 *
115 ******************************************************************************/
ip2_setup(char * str)116 static int __init ip2_setup(char *str)
117 {
118 int ints[10]; /* 4 boards, 2 parameters + 2 */
119 int i, j;
120
121 str = get_options (str, ARRAY_SIZE(ints), ints);
122
123 for( i = 0, j = 1; i < 4; i++ ) {
124 if( j > ints[0] ) {
125 break;
126 }
127 if( ints[j] >= 0 ) {
128 io[i] = ints[j];
129 }
130 j++;
131 if( j > ints[0] ) {
132 break;
133 }
134 if( ints[j] >= 0 ) {
135 irq[i] = ints[j];
136 }
137 j++;
138 }
139 return 1;
140 }
141
142 int
ip2_init(void)143 ip2_init(void) {
144 return ip2_loadmain(io,irq,(unsigned char *)fip_firm,sizeof(fip_firm));
145 }
146
147 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,13))
148 __setup("ip2=", ip2_setup);
149 __initcall(ip2_init);
150 #endif
151
152 #endif /* !MODULE */
153