aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/parport
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/parport')
-rw-r--r--drivers/parport/Kconfig5
-rw-r--r--drivers/parport/daisy.c51
-rw-r--r--drivers/parport/ieee1284_ops.c62
-rw-r--r--drivers/parport/parport_cs.c120
-rw-r--r--drivers/parport/parport_pc.c36
-rw-r--r--drivers/parport/parport_serial.c2
-rw-r--r--drivers/parport/probe.c199
-rw-r--r--drivers/parport/share.c1
8 files changed, 251 insertions, 225 deletions
diff --git a/drivers/parport/Kconfig b/drivers/parport/Kconfig
index 725a14119f2a..f605dea57224 100644
--- a/drivers/parport/Kconfig
+++ b/drivers/parport/Kconfig
@@ -34,7 +34,7 @@ config PARPORT
34 34
35config PARPORT_PC 35config PARPORT_PC
36 tristate "PC-style hardware" 36 tristate "PC-style hardware"
37 depends on PARPORT && (!SPARC64 || PCI) && !SPARC32 && !M32R 37 depends on PARPORT && (!SPARC64 || PCI) && !SPARC32 && !M32R && !FRV
38 ---help--- 38 ---help---
39 You should say Y here if you have a PC-style parallel port. All 39 You should say Y here if you have a PC-style parallel port. All
40 IBM PC compatible computers and some Alphas have PC-style 40 IBM PC compatible computers and some Alphas have PC-style
@@ -77,7 +77,7 @@ config PARPORT_PC_SUPERIO
77 77
78config PARPORT_PC_PCMCIA 78config PARPORT_PC_PCMCIA
79 tristate "Support for PCMCIA management for PC-style ports" 79 tristate "Support for PCMCIA management for PC-style ports"
80 depends on PARPORT!=n && (PCMCIA!=n && PARPORT_PC=m && PARPORT_PC || PARPORT_PC=y && PCMCIA) 80 depends on PCMCIA && PARPORT_PC
81 help 81 help
82 Say Y here if you need PCMCIA support for your PC-style parallel 82 Say Y here if you need PCMCIA support for your PC-style parallel
83 ports. If unsure, say N. 83 ports. If unsure, say N.
@@ -121,6 +121,7 @@ config PARPORT_GSC
121 tristate 121 tristate
122 default GSC 122 default GSC
123 depends on PARPORT 123 depends on PARPORT
124 select PARPORT_NOT_PC
124 125
125config PARPORT_SUNBPP 126config PARPORT_SUNBPP
126 tristate "Sparc hardware (EXPERIMENTAL)" 127 tristate "Sparc hardware (EXPERIMENTAL)"
diff --git a/drivers/parport/daisy.c b/drivers/parport/daisy.c
index 075c7eb5c85d..9ee67321b630 100644
--- a/drivers/parport/daisy.c
+++ b/drivers/parport/daisy.c
@@ -144,9 +144,9 @@ again:
144 add_dev (numdevs++, port, -1); 144 add_dev (numdevs++, port, -1);
145 145
146 /* Find out the legacy device's IEEE 1284 device ID. */ 146 /* Find out the legacy device's IEEE 1284 device ID. */
147 deviceid = kmalloc (1000, GFP_KERNEL); 147 deviceid = kmalloc (1024, GFP_KERNEL);
148 if (deviceid) { 148 if (deviceid) {
149 if (parport_device_id (numdevs - 1, deviceid, 1000) > 2) 149 if (parport_device_id (numdevs - 1, deviceid, 1024) > 2)
150 detected++; 150 detected++;
151 151
152 kfree (deviceid); 152 kfree (deviceid);
@@ -252,7 +252,7 @@ struct pardevice *parport_open (int devnum, const char *name,
252 selected = port->daisy; 252 selected = port->daisy;
253 parport_release (dev); 253 parport_release (dev);
254 254
255 if (selected != port->daisy) { 255 if (selected != daisy) {
256 /* No corresponding device. */ 256 /* No corresponding device. */
257 parport_unregister_device (dev); 257 parport_unregister_device (dev);
258 return NULL; 258 return NULL;
@@ -344,9 +344,9 @@ static int cpp_daisy (struct parport *port, int cmd)
344 PARPORT_CONTROL_STROBE, 344 PARPORT_CONTROL_STROBE,
345 PARPORT_CONTROL_STROBE); 345 PARPORT_CONTROL_STROBE);
346 udelay (1); 346 udelay (1);
347 s = parport_read_status (port);
347 parport_frob_control (port, PARPORT_CONTROL_STROBE, 0); 348 parport_frob_control (port, PARPORT_CONTROL_STROBE, 0);
348 udelay (1); 349 udelay (1);
349 s = parport_read_status (port);
350 parport_write_data (port, 0xff); udelay (2); 350 parport_write_data (port, 0xff); udelay (2);
351 351
352 return s; 352 return s;
@@ -395,15 +395,15 @@ int parport_daisy_select (struct parport *port, int daisy, int mode)
395 case IEEE1284_MODE_EPP: 395 case IEEE1284_MODE_EPP:
396 case IEEE1284_MODE_EPPSL: 396 case IEEE1284_MODE_EPPSL:
397 case IEEE1284_MODE_EPPSWE: 397 case IEEE1284_MODE_EPPSWE:
398 return (cpp_daisy (port, 0x20 + daisy) & 398 return !(cpp_daisy (port, 0x20 + daisy) &
399 PARPORT_STATUS_ERROR); 399 PARPORT_STATUS_ERROR);
400 400
401 // For these modes we should switch to ECP mode: 401 // For these modes we should switch to ECP mode:
402 case IEEE1284_MODE_ECP: 402 case IEEE1284_MODE_ECP:
403 case IEEE1284_MODE_ECPRLE: 403 case IEEE1284_MODE_ECPRLE:
404 case IEEE1284_MODE_ECPSWE: 404 case IEEE1284_MODE_ECPSWE:
405 return (cpp_daisy (port, 0xd0 + daisy) & 405 return !(cpp_daisy (port, 0xd0 + daisy) &
406 PARPORT_STATUS_ERROR); 406 PARPORT_STATUS_ERROR);
407 407
408 // Nothing was told for BECP in Daisy chain specification. 408 // Nothing was told for BECP in Daisy chain specification.
409 // May be it's wise to use ECP? 409 // May be it's wise to use ECP?
@@ -413,8 +413,8 @@ int parport_daisy_select (struct parport *port, int daisy, int mode)
413 case IEEE1284_MODE_BYTE: 413 case IEEE1284_MODE_BYTE:
414 case IEEE1284_MODE_COMPAT: 414 case IEEE1284_MODE_COMPAT:
415 default: 415 default:
416 return (cpp_daisy (port, 0xe0 + daisy) & 416 return !(cpp_daisy (port, 0xe0 + daisy) &
417 PARPORT_STATUS_ERROR); 417 PARPORT_STATUS_ERROR);
418 } 418 }
419} 419}
420 420
@@ -436,7 +436,7 @@ static int select_port (struct parport *port)
436 436
437static int assign_addrs (struct parport *port) 437static int assign_addrs (struct parport *port)
438{ 438{
439 unsigned char s, last_dev; 439 unsigned char s;
440 unsigned char daisy; 440 unsigned char daisy;
441 int thisdev = numdevs; 441 int thisdev = numdevs;
442 int detected; 442 int detected;
@@ -472,10 +472,13 @@ static int assign_addrs (struct parport *port)
472 } 472 }
473 473
474 parport_write_data (port, 0x78); udelay (2); 474 parport_write_data (port, 0x78); udelay (2);
475 last_dev = 0; /* We've just been speaking to a device, so we 475 s = parport_read_status (port);
476 know there must be at least _one_ out there. */
477 476
478 for (daisy = 0; daisy < 4; daisy++) { 477 for (daisy = 0;
478 (s & (PARPORT_STATUS_PAPEROUT|PARPORT_STATUS_SELECT))
479 == (PARPORT_STATUS_PAPEROUT|PARPORT_STATUS_SELECT)
480 && daisy < 4;
481 ++daisy) {
479 parport_write_data (port, daisy); 482 parport_write_data (port, daisy);
480 udelay (2); 483 udelay (2);
481 parport_frob_control (port, 484 parport_frob_control (port,
@@ -485,14 +488,18 @@ static int assign_addrs (struct parport *port)
485 parport_frob_control (port, PARPORT_CONTROL_STROBE, 0); 488 parport_frob_control (port, PARPORT_CONTROL_STROBE, 0);
486 udelay (1); 489 udelay (1);
487 490
488 if (last_dev) 491 add_dev (numdevs++, port, daisy);
489 /* No more devices. */
490 break;
491 492
492 last_dev = !(parport_read_status (port) 493 /* See if this device thought it was the last in the
493 & PARPORT_STATUS_BUSY); 494 * chain. */
495 if (!(s & PARPORT_STATUS_BUSY))
496 break;
494 497
495 add_dev (numdevs++, port, daisy); 498 /* We are seeing pass through status now. We see
499 last_dev from next device or if last_dev does not
500 work status lines from some non-daisy chain
501 device. */
502 s = parport_read_status (port);
496 } 503 }
497 504
498 parport_write_data (port, 0xff); udelay (2); 505 parport_write_data (port, 0xff); udelay (2);
@@ -501,11 +508,11 @@ static int assign_addrs (struct parport *port)
501 detected); 508 detected);
502 509
503 /* Ask the new devices to introduce themselves. */ 510 /* Ask the new devices to introduce themselves. */
504 deviceid = kmalloc (1000, GFP_KERNEL); 511 deviceid = kmalloc (1024, GFP_KERNEL);
505 if (!deviceid) return 0; 512 if (!deviceid) return 0;
506 513
507 for (daisy = 0; thisdev < numdevs; thisdev++, daisy++) 514 for (daisy = 0; thisdev < numdevs; thisdev++, daisy++)
508 parport_device_id (thisdev, deviceid, 1000); 515 parport_device_id (thisdev, deviceid, 1024);
509 516
510 kfree (deviceid); 517 kfree (deviceid);
511 return detected; 518 return detected;
diff --git a/drivers/parport/ieee1284_ops.c b/drivers/parport/ieee1284_ops.c
index ce1e2aad8b10..d6c77658231e 100644
--- a/drivers/parport/ieee1284_ops.c
+++ b/drivers/parport/ieee1284_ops.c
@@ -165,17 +165,7 @@ size_t parport_ieee1284_read_nibble (struct parport *port,
165 /* Does the error line indicate end of data? */ 165 /* Does the error line indicate end of data? */
166 if (((i & 1) == 0) && 166 if (((i & 1) == 0) &&
167 (parport_read_status(port) & PARPORT_STATUS_ERROR)) { 167 (parport_read_status(port) & PARPORT_STATUS_ERROR)) {
168 port->physport->ieee1284.phase = IEEE1284_PH_HBUSY_DNA; 168 goto end_of_data;
169 DPRINTK (KERN_DEBUG
170 "%s: No more nibble data (%d bytes)\n",
171 port->name, i/2);
172
173 /* Go to reverse idle phase. */
174 parport_frob_control (port,
175 PARPORT_CONTROL_AUTOFD,
176 PARPORT_CONTROL_AUTOFD);
177 port->physport->ieee1284.phase = IEEE1284_PH_REV_IDLE;
178 break;
179 } 169 }
180 170
181 /* Event 7: Set nAutoFd low. */ 171 /* Event 7: Set nAutoFd low. */
@@ -225,18 +215,25 @@ size_t parport_ieee1284_read_nibble (struct parport *port,
225 byte = nibble; 215 byte = nibble;
226 } 216 }
227 217
228 i /= 2; /* i is now in bytes */
229
230 if (i == len) { 218 if (i == len) {
231 /* Read the last nibble without checking data avail. */ 219 /* Read the last nibble without checking data avail. */
232 port = port->physport; 220 if (parport_read_status (port) & PARPORT_STATUS_ERROR) {
233 if (parport_read_status (port) & PARPORT_STATUS_ERROR) 221 end_of_data:
234 port->ieee1284.phase = IEEE1284_PH_HBUSY_DNA; 222 DPRINTK (KERN_DEBUG
223 "%s: No more nibble data (%d bytes)\n",
224 port->name, i/2);
225
226 /* Go to reverse idle phase. */
227 parport_frob_control (port,
228 PARPORT_CONTROL_AUTOFD,
229 PARPORT_CONTROL_AUTOFD);
230 port->physport->ieee1284.phase = IEEE1284_PH_REV_IDLE;
231 }
235 else 232 else
236 port->ieee1284.phase = IEEE1284_PH_HBUSY_DAVAIL; 233 port->physport->ieee1284.phase = IEEE1284_PH_HBUSY_DAVAIL;
237 } 234 }
238 235
239 return i; 236 return i/2;
240#endif /* IEEE1284 support */ 237#endif /* IEEE1284 support */
241} 238}
242 239
@@ -256,17 +253,7 @@ size_t parport_ieee1284_read_byte (struct parport *port,
256 253
257 /* Data available? */ 254 /* Data available? */
258 if (parport_read_status (port) & PARPORT_STATUS_ERROR) { 255 if (parport_read_status (port) & PARPORT_STATUS_ERROR) {
259 port->physport->ieee1284.phase = IEEE1284_PH_HBUSY_DNA; 256 goto end_of_data;
260 DPRINTK (KERN_DEBUG
261 "%s: No more byte data (%Zd bytes)\n",
262 port->name, count);
263
264 /* Go to reverse idle phase. */
265 parport_frob_control (port,
266 PARPORT_CONTROL_AUTOFD,
267 PARPORT_CONTROL_AUTOFD);
268 port->physport->ieee1284.phase = IEEE1284_PH_REV_IDLE;
269 break;
270 } 257 }
271 258
272 /* Event 14: Place data bus in high impedance state. */ 259 /* Event 14: Place data bus in high impedance state. */
@@ -318,11 +305,20 @@ size_t parport_ieee1284_read_byte (struct parport *port,
318 305
319 if (count == len) { 306 if (count == len) {
320 /* Read the last byte without checking data avail. */ 307 /* Read the last byte without checking data avail. */
321 port = port->physport; 308 if (parport_read_status (port) & PARPORT_STATUS_ERROR) {
322 if (parport_read_status (port) & PARPORT_STATUS_ERROR) 309 end_of_data:
323 port->ieee1284.phase = IEEE1284_PH_HBUSY_DNA; 310 DPRINTK (KERN_DEBUG
311 "%s: No more byte data (%Zd bytes)\n",
312 port->name, count);
313
314 /* Go to reverse idle phase. */
315 parport_frob_control (port,
316 PARPORT_CONTROL_AUTOFD,
317 PARPORT_CONTROL_AUTOFD);
318 port->physport->ieee1284.phase = IEEE1284_PH_REV_IDLE;
319 }
324 else 320 else
325 port->ieee1284.phase = IEEE1284_PH_HBUSY_DAVAIL; 321 port->physport->ieee1284.phase = IEEE1284_PH_HBUSY_DAVAIL;
326 } 322 }
327 323
328 return count; 324 return count;
diff --git a/drivers/parport/parport_cs.c b/drivers/parport/parport_cs.c
index 24e6aacddb74..158d92563259 100644
--- a/drivers/parport/parport_cs.c
+++ b/drivers/parport/parport_cs.c
@@ -87,15 +87,9 @@ typedef struct parport_info_t {
87 struct parport *port; 87 struct parport *port;
88} parport_info_t; 88} parport_info_t;
89 89
90static dev_link_t *parport_attach(void); 90static void parport_detach(struct pcmcia_device *p_dev);
91static void parport_detach(dev_link_t *);
92static void parport_config(dev_link_t *link); 91static void parport_config(dev_link_t *link);
93static void parport_cs_release(dev_link_t *); 92static void parport_cs_release(dev_link_t *);
94static int parport_event(event_t event, int priority,
95 event_callback_args_t *args);
96
97static dev_info_t dev_info = "parport_cs";
98static dev_link_t *dev_list = NULL;
99 93
100/*====================================================================== 94/*======================================================================
101 95
@@ -105,18 +99,16 @@ static dev_link_t *dev_list = NULL;
105 99
106======================================================================*/ 100======================================================================*/
107 101
108static dev_link_t *parport_attach(void) 102static int parport_attach(struct pcmcia_device *p_dev)
109{ 103{
110 parport_info_t *info; 104 parport_info_t *info;
111 dev_link_t *link; 105 dev_link_t *link;
112 client_reg_t client_reg; 106
113 int ret;
114
115 DEBUG(0, "parport_attach()\n"); 107 DEBUG(0, "parport_attach()\n");
116 108
117 /* Create new parport device */ 109 /* Create new parport device */
118 info = kmalloc(sizeof(*info), GFP_KERNEL); 110 info = kmalloc(sizeof(*info), GFP_KERNEL);
119 if (!info) return NULL; 111 if (!info) return -ENOMEM;
120 memset(info, 0, sizeof(*info)); 112 memset(info, 0, sizeof(*info));
121 link = &info->link; link->priv = info; 113 link = &info->link; link->priv = info;
122 114
@@ -127,21 +119,14 @@ static dev_link_t *parport_attach(void)
127 link->conf.Attributes = CONF_ENABLE_IRQ; 119 link->conf.Attributes = CONF_ENABLE_IRQ;
128 link->conf.Vcc = 50; 120 link->conf.Vcc = 50;
129 link->conf.IntType = INT_MEMORY_AND_IO; 121 link->conf.IntType = INT_MEMORY_AND_IO;
130 122
131 /* Register with Card Services */ 123 link->handle = p_dev;
132 link->next = dev_list; 124 p_dev->instance = link;
133 dev_list = link; 125
134 client_reg.dev_info = &dev_info; 126 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
135 client_reg.Version = 0x0210; 127 parport_config(link);
136 client_reg.event_callback_args.client_data = link; 128
137 ret = pcmcia_register_client(&link->handle, &client_reg); 129 return 0;
138 if (ret != CS_SUCCESS) {
139 cs_error(link->handle, RegisterClient, ret);
140 parport_detach(link);
141 return NULL;
142 }
143
144 return link;
145} /* parport_attach */ 130} /* parport_attach */
146 131
147/*====================================================================== 132/*======================================================================
@@ -153,32 +138,16 @@ static dev_link_t *parport_attach(void)
153 138
154======================================================================*/ 139======================================================================*/
155 140
156static void parport_detach(dev_link_t *link) 141static void parport_detach(struct pcmcia_device *p_dev)
157{ 142{
158 dev_link_t **linkp; 143 dev_link_t *link = dev_to_instance(p_dev);
159 int ret;
160 144
161 DEBUG(0, "parport_detach(0x%p)\n", link); 145 DEBUG(0, "parport_detach(0x%p)\n", link);
162
163 /* Locate device structure */
164 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
165 if (*linkp == link) break;
166 if (*linkp == NULL)
167 return;
168 146
169 if (link->state & DEV_CONFIG) 147 if (link->state & DEV_CONFIG)
170 parport_cs_release(link); 148 parport_cs_release(link);
171 149
172 if (link->handle) {
173 ret = pcmcia_deregister_client(link->handle);
174 if (ret != CS_SUCCESS)
175 cs_error(link->handle, DeregisterClient, ret);
176 }
177
178 /* Unlink, free device structure */
179 *linkp = link->next;
180 kfree(link->priv); 150 kfree(link->priv);
181
182} /* parport_detach */ 151} /* parport_detach */
183 152
184/*====================================================================== 153/*======================================================================
@@ -325,47 +294,27 @@ void parport_cs_release(dev_link_t *link)
325 294
326} /* parport_cs_release */ 295} /* parport_cs_release */
327 296
328/*====================================================================== 297static int parport_suspend(struct pcmcia_device *dev)
329
330 The card status event handler. Mostly, this schedules other
331 stuff to run after an event is received.
332
333======================================================================*/
334
335int parport_event(event_t event, int priority,
336 event_callback_args_t *args)
337{ 298{
338 dev_link_t *link = args->client_data; 299 dev_link_t *link = dev_to_instance(dev);
339 300
340 DEBUG(1, "parport_event(0x%06x)\n", event);
341
342 switch (event) {
343 case CS_EVENT_CARD_REMOVAL:
344 link->state &= ~DEV_PRESENT;
345 if (link->state & DEV_CONFIG)
346 parport_cs_release(link);
347 break;
348 case CS_EVENT_CARD_INSERTION:
349 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
350 parport_config(link);
351 break;
352 case CS_EVENT_PM_SUSPEND:
353 link->state |= DEV_SUSPEND; 301 link->state |= DEV_SUSPEND;
354 /* Fall through... */
355 case CS_EVENT_RESET_PHYSICAL:
356 if (link->state & DEV_CONFIG) 302 if (link->state & DEV_CONFIG)
357 pcmcia_release_configuration(link->handle); 303 pcmcia_release_configuration(link->handle);
358 break; 304
359 case CS_EVENT_PM_RESUME: 305 return 0;
306}
307
308static int parport_resume(struct pcmcia_device *dev)
309{
310 dev_link_t *link = dev_to_instance(dev);
311
360 link->state &= ~DEV_SUSPEND; 312 link->state &= ~DEV_SUSPEND;
361 /* Fall through... */
362 case CS_EVENT_CARD_RESET:
363 if (DEV_OK(link)) 313 if (DEV_OK(link))
364 pcmcia_request_configuration(link->handle, &link->conf); 314 pcmcia_request_configuration(link->handle, &link->conf);
365 break; 315
366 } 316 return 0;
367 return 0; 317}
368} /* parport_event */
369 318
370static struct pcmcia_device_id parport_ids[] = { 319static struct pcmcia_device_id parport_ids[] = {
371 PCMCIA_DEVICE_FUNC_ID(3), 320 PCMCIA_DEVICE_FUNC_ID(3),
@@ -379,11 +328,11 @@ static struct pcmcia_driver parport_cs_driver = {
379 .drv = { 328 .drv = {
380 .name = "parport_cs", 329 .name = "parport_cs",
381 }, 330 },
382 .attach = parport_attach, 331 .probe = parport_attach,
383 .event = parport_event, 332 .remove = parport_detach,
384 .detach = parport_detach,
385 .id_table = parport_ids, 333 .id_table = parport_ids,
386 334 .suspend = parport_suspend,
335 .resume = parport_resume,
387}; 336};
388 337
389static int __init init_parport_cs(void) 338static int __init init_parport_cs(void)
@@ -394,7 +343,6 @@ static int __init init_parport_cs(void)
394static void __exit exit_parport_cs(void) 343static void __exit exit_parport_cs(void)
395{ 344{
396 pcmcia_unregister_driver(&parport_cs_driver); 345 pcmcia_unregister_driver(&parport_cs_driver);
397 BUG_ON(dev_list != NULL);
398} 346}
399 347
400module_init(init_parport_cs); 348module_init(init_parport_cs);
diff --git a/drivers/parport/parport_pc.c b/drivers/parport/parport_pc.c
index c6493ad7c0c8..9302b8fd7461 100644
--- a/drivers/parport/parport_pc.c
+++ b/drivers/parport/parport_pc.c
@@ -1169,7 +1169,7 @@ dump_parport_state ("fwd idle", port);
1169 1169
1170/* GCC is not inlining extern inline function later overwriten to non-inline, 1170/* GCC is not inlining extern inline function later overwriten to non-inline,
1171 so we use outlined_ variants here. */ 1171 so we use outlined_ variants here. */
1172static struct parport_operations parport_pc_ops = 1172static const struct parport_operations parport_pc_ops =
1173{ 1173{
1174 .write_data = parport_pc_write_data, 1174 .write_data = parport_pc_write_data,
1175 .read_data = parport_pc_read_data, 1175 .read_data = parport_pc_read_data,
@@ -1211,10 +1211,11 @@ static struct parport_operations parport_pc_ops =
1211static void __devinit show_parconfig_smsc37c669(int io, int key) 1211static void __devinit show_parconfig_smsc37c669(int io, int key)
1212{ 1212{
1213 int cr1,cr4,cra,cr23,cr26,cr27,i=0; 1213 int cr1,cr4,cra,cr23,cr26,cr27,i=0;
1214 static const char *modes[]={ "SPP and Bidirectional (PS/2)", 1214 static const char *const modes[]={
1215 "EPP and SPP", 1215 "SPP and Bidirectional (PS/2)",
1216 "ECP", 1216 "EPP and SPP",
1217 "ECP and EPP" }; 1217 "ECP",
1218 "ECP and EPP" };
1218 1219
1219 outb(key,io); 1220 outb(key,io);
1220 outb(key,io); 1221 outb(key,io);
@@ -1288,7 +1289,7 @@ static void __devinit show_parconfig_smsc37c669(int io, int key)
1288static void __devinit show_parconfig_winbond(int io, int key) 1289static void __devinit show_parconfig_winbond(int io, int key)
1289{ 1290{
1290 int cr30,cr60,cr61,cr70,cr74,crf0,i=0; 1291 int cr30,cr60,cr61,cr70,cr74,crf0,i=0;
1291 static const char *modes[] = { 1292 static const char *const modes[] = {
1292 "Standard (SPP) and Bidirectional(PS/2)", /* 0 */ 1293 "Standard (SPP) and Bidirectional(PS/2)", /* 0 */
1293 "EPP-1.9 and SPP", 1294 "EPP-1.9 and SPP",
1294 "ECP", 1295 "ECP",
@@ -1297,7 +1298,9 @@ static void __devinit show_parconfig_winbond(int io, int key)
1297 "EPP-1.7 and SPP", /* 5 */ 1298 "EPP-1.7 and SPP", /* 5 */
1298 "undefined!", 1299 "undefined!",
1299 "ECP and EPP-1.7" }; 1300 "ECP and EPP-1.7" };
1300 static char *irqtypes[] = { "pulsed low, high-Z", "follows nACK" }; 1301 static char *const irqtypes[] = {
1302 "pulsed low, high-Z",
1303 "follows nACK" };
1301 1304
1302 /* The registers are called compatible-PnP because the 1305 /* The registers are called compatible-PnP because the
1303 register layout is modelled after ISA-PnP, the access 1306 register layout is modelled after ISA-PnP, the access
@@ -2368,8 +2371,10 @@ void parport_pc_unregister_port (struct parport *p)
2368 spin_lock(&ports_lock); 2371 spin_lock(&ports_lock);
2369 list_del_init(&priv->list); 2372 list_del_init(&priv->list);
2370 spin_unlock(&ports_lock); 2373 spin_unlock(&ports_lock);
2374#if defined(CONFIG_PARPORT_PC_FIFO) && defined(HAS_DMA)
2371 if (p->dma != PARPORT_DMA_NONE) 2375 if (p->dma != PARPORT_DMA_NONE)
2372 free_dma(p->dma); 2376 free_dma(p->dma);
2377#endif
2373 if (p->irq != PARPORT_IRQ_NONE) 2378 if (p->irq != PARPORT_IRQ_NONE)
2374 free_irq(p->irq, p); 2379 free_irq(p->irq, p);
2375 release_region(p->base, 3); 2380 release_region(p->base, 3);
@@ -2377,14 +2382,12 @@ void parport_pc_unregister_port (struct parport *p)
2377 release_region(p->base + 3, p->size - 3); 2382 release_region(p->base + 3, p->size - 3);
2378 if (p->modes & PARPORT_MODE_ECP) 2383 if (p->modes & PARPORT_MODE_ECP)
2379 release_region(p->base_hi, 3); 2384 release_region(p->base_hi, 3);
2380#ifdef CONFIG_PARPORT_PC_FIFO 2385#if defined(CONFIG_PARPORT_PC_FIFO) && defined(HAS_DMA)
2381#ifdef HAS_DMA
2382 if (priv->dma_buf) 2386 if (priv->dma_buf)
2383 pci_free_consistent(priv->dev, PAGE_SIZE, 2387 pci_free_consistent(priv->dev, PAGE_SIZE,
2384 priv->dma_buf, 2388 priv->dma_buf,
2385 priv->dma_handle); 2389 priv->dma_handle);
2386#endif 2390#endif
2387#endif
2388 kfree (p->private_data); 2391 kfree (p->private_data);
2389 parport_put_port(p); 2392 parport_put_port(p);
2390 kfree (ops); /* hope no-one cached it */ 2393 kfree (ops); /* hope no-one cached it */
@@ -2396,7 +2399,8 @@ EXPORT_SYMBOL (parport_pc_unregister_port);
2396 2399
2397/* ITE support maintained by Rich Liu <richliu@poorman.org> */ 2400/* ITE support maintained by Rich Liu <richliu@poorman.org> */
2398static int __devinit sio_ite_8872_probe (struct pci_dev *pdev, int autoirq, 2401static int __devinit sio_ite_8872_probe (struct pci_dev *pdev, int autoirq,
2399 int autodma, struct parport_pc_via_data *via) 2402 int autodma,
2403 const struct parport_pc_via_data *via)
2400{ 2404{
2401 short inta_addr[6] = { 0x2A0, 0x2C0, 0x220, 0x240, 0x1E0 }; 2405 short inta_addr[6] = { 0x2A0, 0x2C0, 0x220, 0x240, 0x1E0 };
2402 struct resource *base_res; 2406 struct resource *base_res;
@@ -2524,7 +2528,8 @@ static struct parport_pc_via_data via_8231_data __devinitdata = {
2524}; 2528};
2525 2529
2526static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq, 2530static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq,
2527 int autodma, struct parport_pc_via_data *via) 2531 int autodma,
2532 const struct parport_pc_via_data *via)
2528{ 2533{
2529 u8 tmp, tmp2, siofunc; 2534 u8 tmp, tmp2, siofunc;
2530 u8 ppcontrol = 0; 2535 u8 ppcontrol = 0;
@@ -2694,8 +2699,9 @@ enum parport_pc_sio_types {
2694 2699
2695/* each element directly indexed from enum list, above */ 2700/* each element directly indexed from enum list, above */
2696static struct parport_pc_superio { 2701static struct parport_pc_superio {
2697 int (*probe) (struct pci_dev *pdev, int autoirq, int autodma, struct parport_pc_via_data *via); 2702 int (*probe) (struct pci_dev *pdev, int autoirq, int autodma,
2698 struct parport_pc_via_data *via; 2703 const struct parport_pc_via_data *via);
2704 const struct parport_pc_via_data *via;
2699} parport_pc_superio_info[] __devinitdata = { 2705} parport_pc_superio_info[] __devinitdata = {
2700 { sio_via_probe, &via_686a_data, }, 2706 { sio_via_probe, &via_686a_data, },
2701 { sio_via_probe, &via_8231_data, }, 2707 { sio_via_probe, &via_8231_data, },
@@ -2828,7 +2834,7 @@ static struct parport_pc_pci {
2828 /* netmos_9815 */ { 2, { { 0, -1 }, { 2, -1 }, } }, /* untested */ 2834 /* netmos_9815 */ { 2, { { 0, -1 }, { 2, -1 }, } }, /* untested */
2829}; 2835};
2830 2836
2831static struct pci_device_id parport_pc_pci_tbl[] = { 2837static const struct pci_device_id parport_pc_pci_tbl[] = {
2832 /* Super-IO onboard chips */ 2838 /* Super-IO onboard chips */
2833 { 0x1106, 0x0686, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_via_686a }, 2839 { 0x1106, 0x0686, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_via_686a },
2834 { 0x1106, 0x8231, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_via_8231 }, 2840 { 0x1106, 0x8231, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_via_8231 },
diff --git a/drivers/parport/parport_serial.c b/drivers/parport/parport_serial.c
index d3dad0aac7cb..76dd077e3184 100644
--- a/drivers/parport/parport_serial.c
+++ b/drivers/parport/parport_serial.c
@@ -464,7 +464,7 @@ static struct pci_driver parport_serial_pci_driver = {
464 464
465static int __init parport_serial_init (void) 465static int __init parport_serial_init (void)
466{ 466{
467 return pci_module_init (&parport_serial_pci_driver); 467 return pci_register_driver (&parport_serial_pci_driver);
468} 468}
469 469
470static void __exit parport_serial_exit (void) 470static void __exit parport_serial_exit (void)
diff --git a/drivers/parport/probe.c b/drivers/parport/probe.c
index 4b48b31ec235..b62aee8de3cb 100644
--- a/drivers/parport/probe.c
+++ b/drivers/parport/probe.c
@@ -11,9 +11,9 @@
11#include <linux/string.h> 11#include <linux/string.h>
12#include <asm/uaccess.h> 12#include <asm/uaccess.h>
13 13
14static struct { 14static const struct {
15 char *token; 15 const char *token;
16 char *descr; 16 const char *descr;
17} classes[] = { 17} classes[] = {
18 { "", "Legacy device" }, 18 { "", "Legacy device" },
19 { "PRINTER", "Printer" }, 19 { "PRINTER", "Printer" },
@@ -128,8 +128,131 @@ static void parse_data(struct parport *port, int device, char *str)
128 kfree(txt); 128 kfree(txt);
129} 129}
130 130
131/* Read up to count-1 bytes of device id. Terminate buffer with
132 * '\0'. Buffer begins with two Device ID length bytes as given by
133 * device. */
134static ssize_t parport_read_device_id (struct parport *port, char *buffer,
135 size_t count)
136{
137 unsigned char length[2];
138 unsigned lelen, belen;
139 size_t idlens[4];
140 unsigned numidlens;
141 unsigned current_idlen;
142 ssize_t retval;
143 size_t len;
144
145 /* First two bytes are MSB,LSB of inclusive length. */
146 retval = parport_read (port, length, 2);
147
148 if (retval < 0)
149 return retval;
150 if (retval != 2)
151 return -EIO;
152
153 if (count < 2)
154 return 0;
155 memcpy(buffer, length, 2);
156 len = 2;
157
158 /* Some devices wrongly send LE length, and some send it two
159 * bytes short. Construct a sorted array of lengths to try. */
160 belen = (length[0] << 8) + length[1];
161 lelen = (length[1] << 8) + length[0];
162 idlens[0] = min(belen, lelen);
163 idlens[1] = idlens[0]+2;
164 if (belen != lelen) {
165 int off = 2;
166 /* Don't try lenghts of 0x100 and 0x200 as 1 and 2 */
167 if (idlens[0] <= 2)
168 off = 0;
169 idlens[off] = max(belen, lelen);
170 idlens[off+1] = idlens[off]+2;
171 numidlens = off+2;
172 }
173 else {
174 /* Some devices don't truly implement Device ID, but
175 * just return constant nibble forever. This catches
176 * also those cases. */
177 if (idlens[0] == 0 || idlens[0] > 0xFFF) {
178 printk (KERN_DEBUG "%s: reported broken Device ID"
179 " length of %#zX bytes\n",
180 port->name, idlens[0]);
181 return -EIO;
182 }
183 numidlens = 2;
184 }
185
186 /* Try to respect the given ID length despite all the bugs in
187 * the ID length. Read according to shortest possible ID
188 * first. */
189 for (current_idlen = 0; current_idlen < numidlens; ++current_idlen) {
190 size_t idlen = idlens[current_idlen];
191 if (idlen+1 >= count)
192 break;
193
194 retval = parport_read (port, buffer+len, idlen-len);
195
196 if (retval < 0)
197 return retval;
198 len += retval;
199
200 if (port->physport->ieee1284.phase != IEEE1284_PH_HBUSY_DAVAIL) {
201 if (belen != len) {
202 printk (KERN_DEBUG "%s: Device ID was %d bytes"
203 " while device told it would be %d"
204 " bytes\n",
205 port->name, len, belen);
206 }
207 goto done;
208 }
209
210 /* This might end reading the Device ID too
211 * soon. Hopefully the needed fields were already in
212 * the first 256 bytes or so that we must have read so
213 * far. */
214 if (buffer[len-1] == ';') {
215 printk (KERN_DEBUG "%s: Device ID reading stopped"
216 " before device told data not available. "
217 "Current idlen %d of %d, len bytes %02X %02X\n",
218 port->name, current_idlen, numidlens,
219 length[0], length[1]);
220 goto done;
221 }
222 }
223 if (current_idlen < numidlens) {
224 /* Buffer not large enough, read to end of buffer. */
225 size_t idlen, len2;
226 if (len+1 < count) {
227 retval = parport_read (port, buffer+len, count-len-1);
228 if (retval < 0)
229 return retval;
230 len += retval;
231 }
232 /* Read the whole ID since some devices would not
233 * otherwise give back the Device ID from beginning
234 * next time when asked. */
235 idlen = idlens[current_idlen];
236 len2 = len;
237 while(len2 < idlen && retval > 0) {
238 char tmp[4];
239 retval = parport_read (port, tmp,
240 min(sizeof tmp, idlen-len2));
241 if (retval < 0)
242 return retval;
243 len2 += retval;
244 }
245 }
246 /* In addition, there are broken devices out there that don't
247 even finish off with a semi-colon. We do not need to care
248 about those at this time. */
249 done:
250 buffer[len] = '\0';
251 return len;
252}
253
131/* Get Std 1284 Device ID. */ 254/* Get Std 1284 Device ID. */
132ssize_t parport_device_id (int devnum, char *buffer, size_t len) 255ssize_t parport_device_id (int devnum, char *buffer, size_t count)
133{ 256{
134 ssize_t retval = -ENXIO; 257 ssize_t retval = -ENXIO;
135 struct pardevice *dev = parport_open (devnum, "Device ID probe", 258 struct pardevice *dev = parport_open (devnum, "Device ID probe",
@@ -139,76 +262,20 @@ ssize_t parport_device_id (int devnum, char *buffer, size_t len)
139 262
140 parport_claim_or_block (dev); 263 parport_claim_or_block (dev);
141 264
142 /* Negotiate to compatibility mode, and then to device ID mode. 265 /* Negotiate to compatibility mode, and then to device ID
143 * (This is in case we are already in device ID mode.) */ 266 * mode. (This so that we start form beginning of device ID if
267 * already in device ID mode.) */
144 parport_negotiate (dev->port, IEEE1284_MODE_COMPAT); 268 parport_negotiate (dev->port, IEEE1284_MODE_COMPAT);
145 retval = parport_negotiate (dev->port, 269 retval = parport_negotiate (dev->port,
146 IEEE1284_MODE_NIBBLE | IEEE1284_DEVICEID); 270 IEEE1284_MODE_NIBBLE | IEEE1284_DEVICEID);
147 271
148 if (!retval) { 272 if (!retval) {
149 int idlen; 273 retval = parport_read_device_id (dev->port, buffer, count);
150 unsigned char length[2];
151
152 /* First two bytes are MSB,LSB of inclusive length. */
153 retval = parport_read (dev->port, length, 2);
154
155 if (retval != 2) goto end_id;
156
157 idlen = (length[0] << 8) + length[1] - 2;
158 /*
159 * Check if the caller-allocated buffer is large enough
160 * otherwise bail out or there will be an at least off by one.
161 */
162 if (idlen + 1 < len)
163 len = idlen;
164 else {
165 retval = -EINVAL;
166 goto out;
167 }
168 retval = parport_read (dev->port, buffer, len);
169
170 if (retval != len)
171 printk (KERN_DEBUG "%s: only read %Zd of %Zd ID bytes\n",
172 dev->port->name, retval,
173 len);
174
175 /* Some printer manufacturers mistakenly believe that
176 the length field is supposed to be _exclusive_.
177 In addition, there are broken devices out there
178 that don't even finish off with a semi-colon. */
179 if (buffer[len - 1] != ';') {
180 ssize_t diff;
181 diff = parport_read (dev->port, buffer + len, 2);
182 retval += diff;
183
184 if (diff)
185 printk (KERN_DEBUG
186 "%s: device reported incorrect "
187 "length field (%d, should be %Zd)\n",
188 dev->port->name, idlen, retval);
189 else {
190 /* One semi-colon short of a device ID. */
191 buffer[len++] = ';';
192 printk (KERN_DEBUG "%s: faking semi-colon\n",
193 dev->port->name);
194
195 /* If we get here, I don't think we
196 need to worry about the possible
197 standard violation of having read
198 more than we were told to. The
199 device is non-compliant anyhow. */
200 }
201 }
202
203 end_id:
204 buffer[len] = '\0';
205 parport_negotiate (dev->port, IEEE1284_MODE_COMPAT); 274 parport_negotiate (dev->port, IEEE1284_MODE_COMPAT);
275 if (retval > 2)
276 parse_data (dev->port, dev->daisy, buffer+2);
206 } 277 }
207 278
208 if (retval > 2)
209 parse_data (dev->port, dev->daisy, buffer);
210
211out:
212 parport_release (dev); 279 parport_release (dev);
213 parport_close (dev); 280 parport_close (dev);
214 return retval; 281 return retval;
diff --git a/drivers/parport/share.c b/drivers/parport/share.c
index 9cb3ab156b09..ea62bed6bc83 100644
--- a/drivers/parport/share.c
+++ b/drivers/parport/share.c
@@ -1002,6 +1002,7 @@ EXPORT_SYMBOL(parport_register_driver);
1002EXPORT_SYMBOL(parport_unregister_driver); 1002EXPORT_SYMBOL(parport_unregister_driver);
1003EXPORT_SYMBOL(parport_register_device); 1003EXPORT_SYMBOL(parport_register_device);
1004EXPORT_SYMBOL(parport_unregister_device); 1004EXPORT_SYMBOL(parport_unregister_device);
1005EXPORT_SYMBOL(parport_get_port);
1005EXPORT_SYMBOL(parport_put_port); 1006EXPORT_SYMBOL(parport_put_port);
1006EXPORT_SYMBOL(parport_find_number); 1007EXPORT_SYMBOL(parport_find_number);
1007EXPORT_SYMBOL(parport_find_base); 1008EXPORT_SYMBOL(parport_find_base);