1 /* Parallel-port initialisation code.
2 *
3 * Authors: David Campbell <campbell@torque.net>
4 * Tim Waugh <tim@cyberelk.demon.co.uk>
5 * Jose Renau <renau@acm.org>
6 *
7 * based on work by Grant Guenther <grant@torque.net>
8 * and Philip Blundell <Philip.Blundell@pobox.com>
9 */
10
11 #include <linux/config.h>
12 #include <linux/module.h>
13 #include <linux/threads.h>
14 #include <linux/string.h>
15 #include <linux/parport.h>
16 #include <linux/errno.h>
17 #include <linux/kernel.h>
18 #include <linux/slab.h>
19 #include <linux/init.h>
20
21 #ifndef MODULE
22 static int io[PARPORT_MAX+1] __initdata = { [0 ... PARPORT_MAX] = 0 };
23 #ifdef CONFIG_PARPORT_PC
24 static int io_hi[PARPORT_MAX+1] __initdata =
25 { [0 ... PARPORT_MAX] = PARPORT_IOHI_AUTO };
26 #endif
27 static int irq[PARPORT_MAX] __initdata = { [0 ... PARPORT_MAX-1] = PARPORT_IRQ_PROBEONLY };
28 static int dma[PARPORT_MAX] __initdata = { [0 ... PARPORT_MAX-1] = PARPORT_DMA_NONE };
29
30 extern int parport_pc_init(int *io, int *io_hi, int *irq, int *dma);
31 extern int parport_sunbpp_init(void);
32 extern int parport_amiga_init(void);
33 extern int parport_mfc3_init(void);
34 extern int parport_atari_init(void);
35
36 static int parport_setup_ptr __initdata = 0;
37
38 /*
39 * Acceptable parameters:
40 *
41 * parport=0
42 * parport=auto
43 * parport=0xBASE[,IRQ[,DMA]]
44 *
45 * IRQ/DMA may be numeric or 'auto' or 'none'
46 */
parport_setup(char * str)47 static int __init parport_setup (char *str)
48 {
49 char *endptr;
50 char *sep;
51 int val;
52
53 if (!str || !*str || (*str == '0' && !*(str+1))) {
54 /* Disable parport if "parport=0" in cmdline */
55 io[0] = PARPORT_DISABLE;
56 return 1;
57 }
58
59 if (!strncmp (str, "auto", 4)) {
60 irq[0] = PARPORT_IRQ_AUTO;
61 dma[0] = PARPORT_DMA_AUTO;
62 return 1;
63 }
64
65 val = simple_strtoul (str, &endptr, 0);
66 if (endptr == str) {
67 printk (KERN_WARNING "parport=%s not understood\n", str);
68 return 1;
69 }
70
71 if (parport_setup_ptr == PARPORT_MAX) {
72 printk(KERN_ERR "parport=%s ignored, too many ports\n", str);
73 return 1;
74 }
75
76 io[parport_setup_ptr] = val;
77 irq[parport_setup_ptr] = PARPORT_IRQ_NONE;
78 dma[parport_setup_ptr] = PARPORT_DMA_NONE;
79
80 sep = strchr (str, ',');
81 if (sep++) {
82 if (!strncmp (sep, "auto", 4))
83 irq[parport_setup_ptr] = PARPORT_IRQ_AUTO;
84 else if (strncmp (sep, "none", 4)) {
85 val = simple_strtoul (sep, &endptr, 0);
86 if (endptr == sep) {
87 printk (KERN_WARNING
88 "parport=%s: irq not understood\n",
89 str);
90 return 1;
91 }
92 irq[parport_setup_ptr] = val;
93 }
94 }
95
96 sep = strchr (sep, ',');
97 if (sep++) {
98 if (!strncmp (sep, "auto", 4))
99 dma[parport_setup_ptr] = PARPORT_DMA_AUTO;
100 else if (!strncmp (sep, "nofifo", 6))
101 dma[parport_setup_ptr] = PARPORT_DMA_NOFIFO;
102 else if (strncmp (sep, "none", 4)) {
103 val = simple_strtoul (sep, &endptr, 0);
104 if (endptr == sep) {
105 printk (KERN_WARNING
106 "parport=%s: dma not understood\n",
107 str);
108 return 1;
109 }
110 dma[parport_setup_ptr] = val;
111 }
112 }
113
114 parport_setup_ptr++;
115 return 1;
116 }
117
118 __setup ("parport=", parport_setup);
119
120 #endif
121
122 #ifdef MODULE
init_module(void)123 int init_module(void)
124 {
125 #ifdef CONFIG_SYSCTL
126 parport_default_proc_register ();
127 #endif
128 return 0;
129 }
130
cleanup_module(void)131 void cleanup_module(void)
132 {
133 #ifdef CONFIG_SYSCTL
134 parport_default_proc_unregister ();
135 #endif
136 }
137
138 #else
139
parport_init(void)140 int __init parport_init (void)
141 {
142 if (io[0] == PARPORT_DISABLE)
143 return 1;
144
145 #ifdef CONFIG_SYSCTL
146 parport_default_proc_register ();
147 #endif
148
149 #ifdef CONFIG_PARPORT_PC
150 parport_pc_init(io, io_hi, irq, dma);
151 #endif
152 #ifdef CONFIG_PARPORT_AMIGA
153 parport_amiga_init();
154 #endif
155 #ifdef CONFIG_PARPORT_MFC3
156 parport_mfc3_init();
157 #endif
158 #ifdef CONFIG_PARPORT_ATARI
159 parport_atari_init();
160 #endif
161 #ifdef CONFIG_PARPORT_ARC
162 parport_arc_init();
163 #endif
164 #ifdef CONFIG_PARPORT_SUNBPP
165 parport_sunbpp_init();
166 #endif
167 return 0;
168 }
169
170 __initcall(parport_init);
171
172 #endif
173
174 /* Exported symbols for modules. */
175
176 EXPORT_SYMBOL(parport_claim);
177 EXPORT_SYMBOL(parport_claim_or_block);
178 EXPORT_SYMBOL(parport_release);
179 EXPORT_SYMBOL(parport_register_port);
180 EXPORT_SYMBOL(parport_announce_port);
181 EXPORT_SYMBOL(parport_unregister_port);
182 EXPORT_SYMBOL(parport_register_driver);
183 EXPORT_SYMBOL(parport_unregister_driver);
184 EXPORT_SYMBOL(parport_register_device);
185 EXPORT_SYMBOL(parport_unregister_device);
186 EXPORT_SYMBOL(parport_enumerate);
187 EXPORT_SYMBOL(parport_get_port);
188 EXPORT_SYMBOL(parport_put_port);
189 EXPORT_SYMBOL(parport_find_number);
190 EXPORT_SYMBOL(parport_find_base);
191 EXPORT_SYMBOL(parport_negotiate);
192 EXPORT_SYMBOL(parport_write);
193 EXPORT_SYMBOL(parport_read);
194 EXPORT_SYMBOL(parport_ieee1284_wakeup);
195 EXPORT_SYMBOL(parport_wait_peripheral);
196 EXPORT_SYMBOL(parport_poll_peripheral);
197 EXPORT_SYMBOL(parport_wait_event);
198 EXPORT_SYMBOL(parport_set_timeout);
199 EXPORT_SYMBOL(parport_ieee1284_interrupt);
200 EXPORT_SYMBOL(parport_ieee1284_ecp_write_data);
201 EXPORT_SYMBOL(parport_ieee1284_ecp_read_data);
202 EXPORT_SYMBOL(parport_ieee1284_ecp_write_addr);
203 EXPORT_SYMBOL(parport_ieee1284_write_compat);
204 EXPORT_SYMBOL(parport_ieee1284_read_nibble);
205 EXPORT_SYMBOL(parport_ieee1284_read_byte);
206 EXPORT_SYMBOL(parport_ieee1284_epp_write_data);
207 EXPORT_SYMBOL(parport_ieee1284_epp_read_data);
208 EXPORT_SYMBOL(parport_ieee1284_epp_write_addr);
209 EXPORT_SYMBOL(parport_ieee1284_epp_read_addr);
210 EXPORT_SYMBOL(parport_proc_register);
211 EXPORT_SYMBOL(parport_proc_unregister);
212 EXPORT_SYMBOL(parport_device_proc_register);
213 EXPORT_SYMBOL(parport_device_proc_unregister);
214 EXPORT_SYMBOL(parport_default_proc_register);
215 EXPORT_SYMBOL(parport_default_proc_unregister);
216 EXPORT_SYMBOL(parport_parse_irqs);
217 EXPORT_SYMBOL(parport_parse_dmas);
218 #ifdef CONFIG_PARPORT_1284
219 EXPORT_SYMBOL(parport_open);
220 EXPORT_SYMBOL(parport_close);
221 EXPORT_SYMBOL(parport_device_id);
222 EXPORT_SYMBOL(parport_device_num);
223 EXPORT_SYMBOL(parport_device_coords);
224 EXPORT_SYMBOL(parport_daisy_deselect_all);
225 EXPORT_SYMBOL(parport_daisy_select);
226 EXPORT_SYMBOL(parport_daisy_init);
227 EXPORT_SYMBOL(parport_find_device);
228 EXPORT_SYMBOL(parport_find_class);
229 #endif
230
inc_parport_count(void)231 void inc_parport_count(void)
232 {
233 #ifdef MODULE
234 MOD_INC_USE_COUNT;
235 #endif
236 }
237
dec_parport_count(void)238 void dec_parport_count(void)
239 {
240 #ifdef MODULE
241 MOD_DEC_USE_COUNT;
242 #endif
243 }
244