blob: 56dd83a45e55dc21360f729c488a213a2a258241 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * IEEE 1284.3 Parallel port daisy chain and multiplexor code
3 *
4 * Copyright (C) 1999, 2000 Tim Waugh <tim@cyberelk.demon.co.uk>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 * ??-12-1998: Initial implementation.
12 * 31-01-1999: Make port-cloning transparent.
13 * 13-02-1999: Move DeviceID technique from parport_probe.
14 * 13-03-1999: Get DeviceID from non-IEEE 1284.3 devices too.
15 * 22-02-2000: Count devices that are actually detected.
16 *
17 * Any part of this program may be used in documents licensed under
18 * the GNU Free Documentation License, Version 1.1 or any later version
19 * published by the Free Software Foundation.
20 */
21
22#include <linux/module.h>
23#include <linux/parport.h>
24#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Ingo Molnar174cd4b2017-02-02 19:15:33 +010026#include <linux/sched/signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28#include <asm/current.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080029#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31#undef DEBUG
32
33#ifdef DEBUG
Matthew Martind32ccc42006-10-03 23:25:14 +020034#define DPRINTK(stuff...) printk(stuff)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#else
36#define DPRINTK(stuff...)
37#endif
38
39static struct daisydev {
40 struct daisydev *next;
41 struct parport *port;
42 int daisy;
43 int devnum;
44} *topology = NULL;
45static DEFINE_SPINLOCK(topology_lock);
46
Carlos Palminhadf4c7562017-08-12 22:45:49 +010047static int numdevs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49/* Forward-declaration of lower-level functions. */
Matthew Martind32ccc42006-10-03 23:25:14 +020050static int mux_present(struct parport *port);
51static int num_mux_ports(struct parport *port);
52static int select_port(struct parport *port);
53static int assign_addrs(struct parport *port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55/* Add a device to the discovered topology. */
Matthew Martind32ccc42006-10-03 23:25:14 +020056static void add_dev(int devnum, struct parport *port, int daisy)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
58 struct daisydev *newdev, **p;
Matthew Martind32ccc42006-10-03 23:25:14 +020059 newdev = kmalloc(sizeof(struct daisydev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 if (newdev) {
61 newdev->port = port;
62 newdev->daisy = daisy;
63 newdev->devnum = devnum;
64 spin_lock(&topology_lock);
65 for (p = &topology; *p && (*p)->devnum<devnum; p = &(*p)->next)
66 ;
67 newdev->next = *p;
68 *p = newdev;
69 spin_unlock(&topology_lock);
70 }
71}
72
73/* Clone a parport (actually, make an alias). */
Matthew Martind32ccc42006-10-03 23:25:14 +020074static struct parport *clone_parport(struct parport *real, int muxport)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
Matthew Martind32ccc42006-10-03 23:25:14 +020076 struct parport *extra = parport_register_port(real->base,
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 real->irq,
78 real->dma,
79 real->ops);
80 if (extra) {
81 extra->portnum = real->portnum;
82 extra->physport = real;
83 extra->muxport = muxport;
84 real->slaves[muxport-1] = extra;
85 }
86
87 return extra;
88}
89
90/* Discover the IEEE1284.3 topology on a port -- muxes and daisy chains.
91 * Return value is number of devices actually detected. */
Matthew Martind32ccc42006-10-03 23:25:14 +020092int parport_daisy_init(struct parport *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
94 int detected = 0;
95 char *deviceid;
96 static const char *th[] = { /*0*/"th", "st", "nd", "rd", "th" };
97 int num_ports;
98 int i;
99 int last_try = 0;
100
101again:
102 /* Because this is called before any other devices exist,
103 * we don't have to claim exclusive access. */
104
105 /* If mux present on normal port, need to create new
106 * parports for each extra port. */
Matthew Martind32ccc42006-10-03 23:25:14 +0200107 if (port->muxport < 0 && mux_present(port) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 /* don't be fooled: a mux must have 2 or 4 ports. */
Matthew Martind32ccc42006-10-03 23:25:14 +0200109 ((num_ports = num_mux_ports(port)) == 2 || num_ports == 4)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 /* Leave original as port zero. */
111 port->muxport = 0;
Matthew Martind32ccc42006-10-03 23:25:14 +0200112 printk(KERN_INFO
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 "%s: 1st (default) port of %d-way multiplexor\n",
114 port->name, num_ports);
115 for (i = 1; i < num_ports; i++) {
116 /* Clone the port. */
Matthew Martind32ccc42006-10-03 23:25:14 +0200117 struct parport *extra = clone_parport(port, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 if (!extra) {
Matthew Martind32ccc42006-10-03 23:25:14 +0200119 if (signal_pending(current))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 break;
121
Matthew Martind32ccc42006-10-03 23:25:14 +0200122 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 continue;
124 }
125
Matthew Martind32ccc42006-10-03 23:25:14 +0200126 printk(KERN_INFO
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 "%s: %d%s port of %d-way multiplexor on %s\n",
128 extra->name, i + 1, th[i + 1], num_ports,
129 port->name);
130
131 /* Analyse that port too. We won't recurse
132 forever because of the 'port->muxport < 0'
133 test above. */
134 parport_daisy_init(extra);
135 }
136 }
137
138 if (port->muxport >= 0)
Matthew Martind32ccc42006-10-03 23:25:14 +0200139 select_port(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Matthew Martind32ccc42006-10-03 23:25:14 +0200141 parport_daisy_deselect_all(port);
142 detected += assign_addrs(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144 /* Count the potential legacy device at the end. */
Matthew Martind32ccc42006-10-03 23:25:14 +0200145 add_dev(numdevs++, port, -1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
147 /* Find out the legacy device's IEEE 1284 device ID. */
Matthew Martind32ccc42006-10-03 23:25:14 +0200148 deviceid = kmalloc(1024, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 if (deviceid) {
Matthew Martind32ccc42006-10-03 23:25:14 +0200150 if (parport_device_id(numdevs - 1, deviceid, 1024) > 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 detected++;
152
Matthew Martind32ccc42006-10-03 23:25:14 +0200153 kfree(deviceid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 }
155
156 if (!detected && !last_try) {
157 /* No devices were detected. Perhaps they are in some
158 funny state; let's try to reset them and see if
159 they wake up. */
Matthew Martind32ccc42006-10-03 23:25:14 +0200160 parport_daisy_fini(port);
161 parport_write_control(port, PARPORT_CONTROL_SELECT);
162 udelay(50);
163 parport_write_control(port,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 PARPORT_CONTROL_SELECT |
165 PARPORT_CONTROL_INIT);
Matthew Martind32ccc42006-10-03 23:25:14 +0200166 udelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 last_try = 1;
168 goto again;
169 }
170
171 return detected;
172}
173
174/* Forget about devices on a physical port. */
Matthew Martind32ccc42006-10-03 23:25:14 +0200175void parport_daisy_fini(struct parport *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176{
177 struct daisydev **p;
178
179 spin_lock(&topology_lock);
180 p = &topology;
181 while (*p) {
182 struct daisydev *dev = *p;
183 if (dev->port != port) {
184 p = &dev->next;
185 continue;
186 }
187 *p = dev->next;
188 kfree(dev);
189 }
190
191 /* Gaps in the numbering could be handled better. How should
192 someone enumerate through all IEEE1284.3 devices in the
193 topology?. */
194 if (!topology) numdevs = 0;
195 spin_unlock(&topology_lock);
196 return;
197}
198
199/**
200 * parport_open - find a device by canonical device number
201 * @devnum: canonical device number
202 * @name: name to associate with the device
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 *
204 * This function is similar to parport_register_device(), except
205 * that it locates a device by its number rather than by the port
206 * it is attached to.
207 *
208 * All parameters except for @devnum are the same as for
209 * parport_register_device(). The return value is the same as
210 * for parport_register_device().
211 **/
212
Jeff Garzik5712cb32007-10-19 02:54:26 -0400213struct pardevice *parport_open(int devnum, const char *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
215 struct daisydev *p = topology;
Sudip Mukherjee1aec4212019-02-13 08:47:06 +0000216 struct pardev_cb par_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 struct parport *port;
218 struct pardevice *dev;
219 int daisy;
220
Sudip Mukherjee1aec4212019-02-13 08:47:06 +0000221 memset(&par_cb, 0, sizeof(par_cb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 spin_lock(&topology_lock);
223 while (p && p->devnum != devnum)
224 p = p->next;
225
226 if (!p) {
227 spin_unlock(&topology_lock);
228 return NULL;
229 }
230
231 daisy = p->daisy;
232 port = parport_get_port(p->port);
233 spin_unlock(&topology_lock);
234
Sudip Mukherjee1aec4212019-02-13 08:47:06 +0000235 dev = parport_register_dev_model(port, name, &par_cb, devnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 parport_put_port(port);
237 if (!dev)
238 return NULL;
239
240 dev->daisy = daisy;
241
242 /* Check that there really is a device to select. */
243 if (daisy >= 0) {
244 int selected;
Matthew Martind32ccc42006-10-03 23:25:14 +0200245 parport_claim_or_block(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 selected = port->daisy;
Matthew Martind32ccc42006-10-03 23:25:14 +0200247 parport_release(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Marko Kohtalac29a75e2006-01-06 00:19:46 -0800249 if (selected != daisy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 /* No corresponding device. */
Matthew Martind32ccc42006-10-03 23:25:14 +0200251 parport_unregister_device(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 return NULL;
253 }
254 }
255
256 return dev;
257}
258
259/**
260 * parport_close - close a device opened with parport_open()
261 * @dev: device to close
262 *
263 * This is to parport_open() as parport_unregister_device() is to
264 * parport_register_device().
265 **/
266
Matthew Martind32ccc42006-10-03 23:25:14 +0200267void parport_close(struct pardevice *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268{
Matthew Martind32ccc42006-10-03 23:25:14 +0200269 parport_unregister_device(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270}
271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272/* Send a daisy-chain-style CPP command packet. */
Matthew Martind32ccc42006-10-03 23:25:14 +0200273static int cpp_daisy(struct parport *port, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
275 unsigned char s;
276
Matthew Martind32ccc42006-10-03 23:25:14 +0200277 parport_data_forward(port);
278 parport_write_data(port, 0xaa); udelay(2);
279 parport_write_data(port, 0x55); udelay(2);
280 parport_write_data(port, 0x00); udelay(2);
281 parport_write_data(port, 0xff); udelay(2);
282 s = parport_read_status(port) & (PARPORT_STATUS_BUSY
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 | PARPORT_STATUS_PAPEROUT
284 | PARPORT_STATUS_SELECT
285 | PARPORT_STATUS_ERROR);
286 if (s != (PARPORT_STATUS_BUSY
287 | PARPORT_STATUS_PAPEROUT
288 | PARPORT_STATUS_SELECT
289 | PARPORT_STATUS_ERROR)) {
Matthew Martind32ccc42006-10-03 23:25:14 +0200290 DPRINTK(KERN_DEBUG "%s: cpp_daisy: aa5500ff(%02x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 port->name, s);
292 return -ENXIO;
293 }
294
Matthew Martind32ccc42006-10-03 23:25:14 +0200295 parport_write_data(port, 0x87); udelay(2);
296 s = parport_read_status(port) & (PARPORT_STATUS_BUSY
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 | PARPORT_STATUS_PAPEROUT
298 | PARPORT_STATUS_SELECT
299 | PARPORT_STATUS_ERROR);
300 if (s != (PARPORT_STATUS_SELECT | PARPORT_STATUS_ERROR)) {
Matthew Martind32ccc42006-10-03 23:25:14 +0200301 DPRINTK(KERN_DEBUG "%s: cpp_daisy: aa5500ff87(%02x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 port->name, s);
303 return -ENXIO;
304 }
305
Matthew Martind32ccc42006-10-03 23:25:14 +0200306 parport_write_data(port, 0x78); udelay(2);
307 parport_write_data(port, cmd); udelay(2);
308 parport_frob_control(port,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 PARPORT_CONTROL_STROBE,
310 PARPORT_CONTROL_STROBE);
Matthew Martind32ccc42006-10-03 23:25:14 +0200311 udelay(1);
312 s = parport_read_status(port);
313 parport_frob_control(port, PARPORT_CONTROL_STROBE, 0);
314 udelay(1);
315 parport_write_data(port, 0xff); udelay(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317 return s;
318}
319
320/* Send a mux-style CPP command packet. */
Matthew Martind32ccc42006-10-03 23:25:14 +0200321static int cpp_mux(struct parport *port, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322{
323 unsigned char s;
324 int rc;
325
Matthew Martind32ccc42006-10-03 23:25:14 +0200326 parport_data_forward(port);
327 parport_write_data(port, 0xaa); udelay(2);
328 parport_write_data(port, 0x55); udelay(2);
329 parport_write_data(port, 0xf0); udelay(2);
330 parport_write_data(port, 0x0f); udelay(2);
331 parport_write_data(port, 0x52); udelay(2);
332 parport_write_data(port, 0xad); udelay(2);
333 parport_write_data(port, cmd); udelay(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Matthew Martind32ccc42006-10-03 23:25:14 +0200335 s = parport_read_status(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 if (!(s & PARPORT_STATUS_ACK)) {
Matthew Martind32ccc42006-10-03 23:25:14 +0200337 DPRINTK(KERN_DEBUG "%s: cpp_mux: aa55f00f52ad%02x(%02x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 port->name, cmd, s);
339 return -EIO;
340 }
341
342 rc = (((s & PARPORT_STATUS_SELECT ? 1 : 0) << 0) |
343 ((s & PARPORT_STATUS_PAPEROUT ? 1 : 0) << 1) |
344 ((s & PARPORT_STATUS_BUSY ? 0 : 1) << 2) |
345 ((s & PARPORT_STATUS_ERROR ? 0 : 1) << 3));
346
347 return rc;
348}
349
Matthew Martind32ccc42006-10-03 23:25:14 +0200350void parport_daisy_deselect_all(struct parport *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{
Matthew Martind32ccc42006-10-03 23:25:14 +0200352 cpp_daisy(port, 0x30);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353}
354
Matthew Martind32ccc42006-10-03 23:25:14 +0200355int parport_daisy_select(struct parport *port, int daisy, int mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
357 switch (mode)
358 {
359 // For these modes we should switch to EPP mode:
360 case IEEE1284_MODE_EPP:
361 case IEEE1284_MODE_EPPSL:
362 case IEEE1284_MODE_EPPSWE:
Matthew Martind32ccc42006-10-03 23:25:14 +0200363 return !(cpp_daisy(port, 0x20 + daisy) &
Marko Kohtala7c9cc3b2006-01-06 00:19:46 -0800364 PARPORT_STATUS_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
366 // For these modes we should switch to ECP mode:
367 case IEEE1284_MODE_ECP:
368 case IEEE1284_MODE_ECPRLE:
369 case IEEE1284_MODE_ECPSWE:
Matthew Martind32ccc42006-10-03 23:25:14 +0200370 return !(cpp_daisy(port, 0xd0 + daisy) &
Marko Kohtala7c9cc3b2006-01-06 00:19:46 -0800371 PARPORT_STATUS_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
373 // Nothing was told for BECP in Daisy chain specification.
374 // May be it's wise to use ECP?
375 case IEEE1284_MODE_BECP:
376 // Others use compat mode
377 case IEEE1284_MODE_NIBBLE:
378 case IEEE1284_MODE_BYTE:
379 case IEEE1284_MODE_COMPAT:
380 default:
Matthew Martind32ccc42006-10-03 23:25:14 +0200381 return !(cpp_daisy(port, 0xe0 + daisy) &
Marko Kohtala7c9cc3b2006-01-06 00:19:46 -0800382 PARPORT_STATUS_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 }
384}
385
Matthew Martind32ccc42006-10-03 23:25:14 +0200386static int mux_present(struct parport *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387{
Matthew Martind32ccc42006-10-03 23:25:14 +0200388 return cpp_mux(port, 0x51) == 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389}
390
Matthew Martind32ccc42006-10-03 23:25:14 +0200391static int num_mux_ports(struct parport *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392{
Matthew Martind32ccc42006-10-03 23:25:14 +0200393 return cpp_mux(port, 0x58);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394}
395
Matthew Martind32ccc42006-10-03 23:25:14 +0200396static int select_port(struct parport *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397{
398 int muxport = port->muxport;
Matthew Martind32ccc42006-10-03 23:25:14 +0200399 return cpp_mux(port, 0x60 + muxport) == muxport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400}
401
Matthew Martind32ccc42006-10-03 23:25:14 +0200402static int assign_addrs(struct parport *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Marko Kohtala310c8c32006-01-06 00:19:45 -0800404 unsigned char s;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 unsigned char daisy;
406 int thisdev = numdevs;
407 int detected;
408 char *deviceid;
409
Matthew Martind32ccc42006-10-03 23:25:14 +0200410 parport_data_forward(port);
411 parport_write_data(port, 0xaa); udelay(2);
412 parport_write_data(port, 0x55); udelay(2);
413 parport_write_data(port, 0x00); udelay(2);
414 parport_write_data(port, 0xff); udelay(2);
415 s = parport_read_status(port) & (PARPORT_STATUS_BUSY
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 | PARPORT_STATUS_PAPEROUT
417 | PARPORT_STATUS_SELECT
418 | PARPORT_STATUS_ERROR);
419 if (s != (PARPORT_STATUS_BUSY
420 | PARPORT_STATUS_PAPEROUT
421 | PARPORT_STATUS_SELECT
422 | PARPORT_STATUS_ERROR)) {
Matthew Martind32ccc42006-10-03 23:25:14 +0200423 DPRINTK(KERN_DEBUG "%s: assign_addrs: aa5500ff(%02x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 port->name, s);
425 return 0;
426 }
427
Matthew Martind32ccc42006-10-03 23:25:14 +0200428 parport_write_data(port, 0x87); udelay(2);
429 s = parport_read_status(port) & (PARPORT_STATUS_BUSY
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 | PARPORT_STATUS_PAPEROUT
431 | PARPORT_STATUS_SELECT
432 | PARPORT_STATUS_ERROR);
433 if (s != (PARPORT_STATUS_SELECT | PARPORT_STATUS_ERROR)) {
Matthew Martind32ccc42006-10-03 23:25:14 +0200434 DPRINTK(KERN_DEBUG "%s: assign_addrs: aa5500ff87(%02x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 port->name, s);
436 return 0;
437 }
438
Matthew Martind32ccc42006-10-03 23:25:14 +0200439 parport_write_data(port, 0x78); udelay(2);
440 s = parport_read_status(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
Marko Kohtala310c8c32006-01-06 00:19:45 -0800442 for (daisy = 0;
443 (s & (PARPORT_STATUS_PAPEROUT|PARPORT_STATUS_SELECT))
444 == (PARPORT_STATUS_PAPEROUT|PARPORT_STATUS_SELECT)
445 && daisy < 4;
446 ++daisy) {
Matthew Martind32ccc42006-10-03 23:25:14 +0200447 parport_write_data(port, daisy);
448 udelay(2);
449 parport_frob_control(port,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 PARPORT_CONTROL_STROBE,
451 PARPORT_CONTROL_STROBE);
Matthew Martind32ccc42006-10-03 23:25:14 +0200452 udelay(1);
453 parport_frob_control(port, PARPORT_CONTROL_STROBE, 0);
454 udelay(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Matthew Martind32ccc42006-10-03 23:25:14 +0200456 add_dev(numdevs++, port, daisy);
Marko Kohtala310c8c32006-01-06 00:19:45 -0800457
458 /* See if this device thought it was the last in the
459 * chain. */
460 if (!(s & PARPORT_STATUS_BUSY))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 break;
462
Marko Kohtala310c8c32006-01-06 00:19:45 -0800463 /* We are seeing pass through status now. We see
464 last_dev from next device or if last_dev does not
465 work status lines from some non-daisy chain
466 device. */
Matthew Martind32ccc42006-10-03 23:25:14 +0200467 s = parport_read_status(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 }
469
Matthew Martind32ccc42006-10-03 23:25:14 +0200470 parport_write_data(port, 0xff); udelay(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 detected = numdevs - thisdev;
Matthew Martind32ccc42006-10-03 23:25:14 +0200472 DPRINTK(KERN_DEBUG "%s: Found %d daisy-chained devices\n", port->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 detected);
474
475 /* Ask the new devices to introduce themselves. */
Matthew Martind32ccc42006-10-03 23:25:14 +0200476 deviceid = kmalloc(1024, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 if (!deviceid) return 0;
478
479 for (daisy = 0; thisdev < numdevs; thisdev++, daisy++)
Matthew Martind32ccc42006-10-03 23:25:14 +0200480 parport_device_id(thisdev, deviceid, 1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Matthew Martind32ccc42006-10-03 23:25:14 +0200482 kfree(deviceid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 return detected;
484}
Sudip Mukherjee1aec4212019-02-13 08:47:06 +0000485
486static int daisy_drv_probe(struct pardevice *par_dev)
487{
488 struct device_driver *drv = par_dev->dev.driver;
489
490 if (strcmp(drv->name, "daisy_drv"))
491 return -ENODEV;
492 if (strcmp(par_dev->name, daisy_dev_name))
493 return -ENODEV;
494
495 return 0;
496}
497
498static struct parport_driver daisy_driver = {
499 .name = "daisy_drv",
500 .probe = daisy_drv_probe,
501 .devmodel = true,
502};
503
504int daisy_drv_init(void)
505{
506 return parport_register_driver(&daisy_driver);
507}
508
509void daisy_drv_exit(void)
510{
511 parport_unregister_driver(&daisy_driver);
512}