allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / drivers / macintosh / adb.c
blobadfea3c7c62af3a2a8dca67a4b14a5eefa8e32e3
1 /*
2 * Device driver for the Apple Desktop Bus
3 * and the /dev/adb device on macintoshes.
5 * Copyright (C) 1996 Paul Mackerras.
7 * Modified to declare controllers as structures, added
8 * client notification of bus reset and handles PowerBook
9 * sleep, by Benjamin Herrenschmidt.
11 * To do:
13 * - /sys/bus/adb to list the devices and infos
14 * - more /dev/adb to allow userland to receive the
15 * flow of auto-polling datas from a given device.
16 * - move bus probe to a kernel thread
19 #include <linux/types.h>
20 #include <linux/errno.h>
21 #include <linux/kernel.h>
22 #include <linux/slab.h>
23 #include <linux/module.h>
24 #include <linux/fs.h>
25 #include <linux/mm.h>
26 #include <linux/sched.h>
27 #include <linux/smp_lock.h>
28 #include <linux/adb.h>
29 #include <linux/cuda.h>
30 #include <linux/pmu.h>
31 #include <linux/notifier.h>
32 #include <linux/wait.h>
33 #include <linux/init.h>
34 #include <linux/delay.h>
35 #include <linux/spinlock.h>
36 #include <linux/completion.h>
37 #include <linux/device.h>
39 #include <asm/uaccess.h>
40 #include <asm/semaphore.h>
41 #ifdef CONFIG_PPC
42 #include <asm/prom.h>
43 #include <asm/machdep.h>
44 #endif
47 EXPORT_SYMBOL(adb_controller);
48 EXPORT_SYMBOL(adb_client_list);
50 extern struct adb_driver via_macii_driver;
51 extern struct adb_driver via_maciisi_driver;
52 extern struct adb_driver via_cuda_driver;
53 extern struct adb_driver adb_iop_driver;
54 extern struct adb_driver via_pmu_driver;
55 extern struct adb_driver macio_adb_driver;
57 static struct adb_driver *adb_driver_list[] = {
58 #ifdef CONFIG_ADB_MACII
59 &via_macii_driver,
60 #endif
61 #ifdef CONFIG_ADB_MACIISI
62 &via_maciisi_driver,
63 #endif
64 #ifdef CONFIG_ADB_CUDA
65 &via_cuda_driver,
66 #endif
67 #ifdef CONFIG_ADB_IOP
68 &adb_iop_driver,
69 #endif
70 #if defined(CONFIG_ADB_PMU) || defined(CONFIG_ADB_PMU68K)
71 &via_pmu_driver,
72 #endif
73 #ifdef CONFIG_ADB_MACIO
74 &macio_adb_driver,
75 #endif
76 NULL
79 static struct class *adb_dev_class;
81 struct adb_driver *adb_controller;
82 BLOCKING_NOTIFIER_HEAD(adb_client_list);
83 static int adb_got_sleep;
84 static int adb_inited;
85 static pid_t adb_probe_task_pid;
86 static DECLARE_MUTEX(adb_probe_mutex);
87 static struct completion adb_probe_task_comp;
88 static int sleepy_trackpad;
89 static int autopoll_devs;
90 int __adb_probe_sync;
92 #ifdef CONFIG_PM
93 static void adb_notify_sleep(struct pmu_sleep_notifier *self, int when);
94 static struct pmu_sleep_notifier adb_sleep_notifier = {
95 adb_notify_sleep,
96 SLEEP_LEVEL_ADB,
98 #endif
100 static int adb_scan_bus(void);
101 static int do_adb_reset_bus(void);
102 static void adbdev_init(void);
103 static int try_handler_change(int, int);
105 static struct adb_handler {
106 void (*handler)(unsigned char *, int, int);
107 int original_address;
108 int handler_id;
109 int busy;
110 } adb_handler[16];
113 * The adb_handler_sem mutex protects all accesses to the original_address
114 * and handler_id fields of adb_handler[i] for all i, and changes to the
115 * handler field.
116 * Accesses to the handler field are protected by the adb_handler_lock
117 * rwlock. It is held across all calls to any handler, so that by the
118 * time adb_unregister returns, we know that the old handler isn't being
119 * called.
121 static DECLARE_MUTEX(adb_handler_sem);
122 static DEFINE_RWLOCK(adb_handler_lock);
124 #if 0
125 static void printADBreply(struct adb_request *req)
127 int i;
129 printk("adb reply (%d)", req->reply_len);
130 for(i = 0; i < req->reply_len; i++)
131 printk(" %x", req->reply[i]);
132 printk("\n");
135 #endif
138 static __inline__ void adb_wait_ms(unsigned int ms)
140 if (current->pid && adb_probe_task_pid &&
141 adb_probe_task_pid == current->pid)
142 msleep(ms);
143 else
144 mdelay(ms);
147 static int adb_scan_bus(void)
149 int i, highFree=0, noMovement;
150 int devmask = 0;
151 struct adb_request req;
153 /* assumes adb_handler[] is all zeroes at this point */
154 for (i = 1; i < 16; i++) {
155 /* see if there is anything at address i */
156 adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
157 (i << 4) | 0xf);
158 if (req.reply_len > 1)
159 /* one or more devices at this address */
160 adb_handler[i].original_address = i;
161 else if (i > highFree)
162 highFree = i;
165 /* Note we reset noMovement to 0 each time we move a device */
166 for (noMovement = 1; noMovement < 2 && highFree > 0; noMovement++) {
167 for (i = 1; i < 16; i++) {
168 if (adb_handler[i].original_address == 0)
169 continue;
171 * Send a "talk register 3" command to address i
172 * to provoke a collision if there is more than
173 * one device at this address.
175 adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
176 (i << 4) | 0xf);
178 * Move the device(s) which didn't detect a
179 * collision to address `highFree'. Hopefully
180 * this only moves one device.
182 adb_request(&req, NULL, ADBREQ_SYNC, 3,
183 (i<< 4) | 0xb, (highFree | 0x60), 0xfe);
185 * See if anybody actually moved. This is suggested
186 * by HW TechNote 01:
188 * http://developer.apple.com/technotes/hw/hw_01.html
190 adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
191 (highFree << 4) | 0xf);
192 if (req.reply_len <= 1) continue;
194 * Test whether there are any device(s) left
195 * at address i.
197 adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
198 (i << 4) | 0xf);
199 if (req.reply_len > 1) {
201 * There are still one or more devices
202 * left at address i. Register the one(s)
203 * we moved to `highFree', and find a new
204 * value for highFree.
206 adb_handler[highFree].original_address =
207 adb_handler[i].original_address;
208 while (highFree > 0 &&
209 adb_handler[highFree].original_address)
210 highFree--;
211 if (highFree <= 0)
212 break;
214 noMovement = 0;
216 else {
218 * No devices left at address i; move the
219 * one(s) we moved to `highFree' back to i.
221 adb_request(&req, NULL, ADBREQ_SYNC, 3,
222 (highFree << 4) | 0xb,
223 (i | 0x60), 0xfe);
228 /* Now fill in the handler_id field of the adb_handler entries. */
229 printk(KERN_DEBUG "adb devices:");
230 for (i = 1; i < 16; i++) {
231 if (adb_handler[i].original_address == 0)
232 continue;
233 adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
234 (i << 4) | 0xf);
235 adb_handler[i].handler_id = req.reply[2];
236 printk(" [%d]: %d %x", i, adb_handler[i].original_address,
237 adb_handler[i].handler_id);
238 devmask |= 1 << i;
240 printk("\n");
241 return devmask;
245 * This kernel task handles ADB probing. It dies once probing is
246 * completed.
248 static int
249 adb_probe_task(void *x)
251 sigset_t blocked;
253 strcpy(current->comm, "kadbprobe");
255 sigfillset(&blocked);
256 sigprocmask(SIG_BLOCK, &blocked, NULL);
257 flush_signals(current);
259 printk(KERN_INFO "adb: starting probe task...\n");
260 do_adb_reset_bus();
261 printk(KERN_INFO "adb: finished probe task...\n");
263 adb_probe_task_pid = 0;
264 up(&adb_probe_mutex);
266 return 0;
269 static void
270 __adb_probe_task(struct work_struct *bullshit)
272 adb_probe_task_pid = kernel_thread(adb_probe_task, NULL, SIGCHLD | CLONE_KERNEL);
275 static DECLARE_WORK(adb_reset_work, __adb_probe_task);
278 adb_reset_bus(void)
280 if (__adb_probe_sync) {
281 do_adb_reset_bus();
282 return 0;
285 down(&adb_probe_mutex);
286 schedule_work(&adb_reset_work);
287 return 0;
290 int __init adb_init(void)
292 struct adb_driver *driver;
293 int i;
295 #ifdef CONFIG_PPC32
296 if (!machine_is(chrp) && !machine_is(powermac))
297 return 0;
298 #endif
299 #ifdef CONFIG_MAC
300 if (!MACH_IS_MAC)
301 return 0;
302 #endif
304 /* xmon may do early-init */
305 if (adb_inited)
306 return 0;
307 adb_inited = 1;
309 adb_controller = NULL;
311 i = 0;
312 while ((driver = adb_driver_list[i++]) != NULL) {
313 if (!driver->probe()) {
314 adb_controller = driver;
315 break;
318 if ((adb_controller == NULL) || adb_controller->init()) {
319 printk(KERN_WARNING "Warning: no ADB interface detected\n");
320 adb_controller = NULL;
321 } else {
322 #ifdef CONFIG_PM
323 pmu_register_sleep_notifier(&adb_sleep_notifier);
324 #endif /* CONFIG_PM */
325 #ifdef CONFIG_PPC
326 if (machine_is_compatible("AAPL,PowerBook1998") ||
327 machine_is_compatible("PowerBook1,1"))
328 sleepy_trackpad = 1;
329 #endif /* CONFIG_PPC */
330 init_completion(&adb_probe_task_comp);
331 adbdev_init();
332 adb_reset_bus();
334 return 0;
337 __initcall(adb_init);
339 #ifdef CONFIG_PM
341 * notify clients before sleep and reset bus afterwards
343 void
344 adb_notify_sleep(struct pmu_sleep_notifier *self, int when)
346 switch (when) {
347 case PBOOK_SLEEP_REQUEST:
348 adb_got_sleep = 1;
349 /* We need to get a lock on the probe thread */
350 down(&adb_probe_mutex);
351 /* Stop autopoll */
352 if (adb_controller->autopoll)
353 adb_controller->autopoll(0);
354 blocking_notifier_call_chain(&adb_client_list,
355 ADB_MSG_POWERDOWN, NULL);
356 break;
357 case PBOOK_WAKE:
358 adb_got_sleep = 0;
359 up(&adb_probe_mutex);
360 adb_reset_bus();
361 break;
364 #endif /* CONFIG_PM */
366 static int
367 do_adb_reset_bus(void)
369 int ret;
371 if (adb_controller == NULL)
372 return -ENXIO;
374 if (adb_controller->autopoll)
375 adb_controller->autopoll(0);
377 blocking_notifier_call_chain(&adb_client_list,
378 ADB_MSG_PRE_RESET, NULL);
380 if (sleepy_trackpad) {
381 /* Let the trackpad settle down */
382 adb_wait_ms(500);
385 down(&adb_handler_sem);
386 write_lock_irq(&adb_handler_lock);
387 memset(adb_handler, 0, sizeof(adb_handler));
388 write_unlock_irq(&adb_handler_lock);
390 /* That one is still a bit synchronous, oh well... */
391 if (adb_controller->reset_bus)
392 ret = adb_controller->reset_bus();
393 else
394 ret = 0;
396 if (sleepy_trackpad) {
397 /* Let the trackpad settle down */
398 adb_wait_ms(1500);
401 if (!ret) {
402 autopoll_devs = adb_scan_bus();
403 if (adb_controller->autopoll)
404 adb_controller->autopoll(autopoll_devs);
406 up(&adb_handler_sem);
408 blocking_notifier_call_chain(&adb_client_list,
409 ADB_MSG_POST_RESET, NULL);
411 return ret;
414 void
415 adb_poll(void)
417 if ((adb_controller == NULL)||(adb_controller->poll == NULL))
418 return;
419 adb_controller->poll();
422 static void
423 adb_probe_wakeup(struct adb_request *req)
425 complete(&adb_probe_task_comp);
428 /* Static request used during probe */
429 static struct adb_request adb_sreq;
430 static unsigned long adb_sreq_lock; // Use semaphore ! */
433 adb_request(struct adb_request *req, void (*done)(struct adb_request *),
434 int flags, int nbytes, ...)
436 va_list list;
437 int i, use_sreq;
438 int rc;
440 if ((adb_controller == NULL) || (adb_controller->send_request == NULL))
441 return -ENXIO;
442 if (nbytes < 1)
443 return -EINVAL;
444 if (req == NULL && (flags & ADBREQ_NOSEND))
445 return -EINVAL;
447 if (req == NULL) {
448 if (test_and_set_bit(0,&adb_sreq_lock)) {
449 printk("adb.c: Warning: contention on static request !\n");
450 return -EPERM;
452 req = &adb_sreq;
453 flags |= ADBREQ_SYNC;
454 use_sreq = 1;
455 } else
456 use_sreq = 0;
457 req->nbytes = nbytes+1;
458 req->done = done;
459 req->reply_expected = flags & ADBREQ_REPLY;
460 req->data[0] = ADB_PACKET;
461 va_start(list, nbytes);
462 for (i = 0; i < nbytes; ++i)
463 req->data[i+1] = va_arg(list, int);
464 va_end(list);
466 if (flags & ADBREQ_NOSEND)
467 return 0;
469 /* Synchronous requests send from the probe thread cause it to
470 * block. Beware that the "done" callback will be overriden !
472 if ((flags & ADBREQ_SYNC) &&
473 (current->pid && adb_probe_task_pid &&
474 adb_probe_task_pid == current->pid)) {
475 req->done = adb_probe_wakeup;
476 rc = adb_controller->send_request(req, 0);
477 if (rc || req->complete)
478 goto bail;
479 wait_for_completion(&adb_probe_task_comp);
480 rc = 0;
481 goto bail;
484 rc = adb_controller->send_request(req, flags & ADBREQ_SYNC);
485 bail:
486 if (use_sreq)
487 clear_bit(0, &adb_sreq_lock);
489 return rc;
492 /* Ultimately this should return the number of devices with
493 the given default id.
494 And it does it now ! Note: changed behaviour: This function
495 will now register if default_id _and_ handler_id both match
496 but handler_id can be left to 0 to match with default_id only.
497 When handler_id is set, this function will try to adjust
498 the handler_id id it doesn't match. */
500 adb_register(int default_id, int handler_id, struct adb_ids *ids,
501 void (*handler)(unsigned char *, int, int))
503 int i;
505 down(&adb_handler_sem);
506 ids->nids = 0;
507 for (i = 1; i < 16; i++) {
508 if ((adb_handler[i].original_address == default_id) &&
509 (!handler_id || (handler_id == adb_handler[i].handler_id) ||
510 try_handler_change(i, handler_id))) {
511 if (adb_handler[i].handler != 0) {
512 printk(KERN_ERR
513 "Two handlers for ADB device %d\n",
514 default_id);
515 continue;
517 write_lock_irq(&adb_handler_lock);
518 adb_handler[i].handler = handler;
519 write_unlock_irq(&adb_handler_lock);
520 ids->id[ids->nids++] = i;
523 up(&adb_handler_sem);
524 return ids->nids;
528 adb_unregister(int index)
530 int ret = -ENODEV;
532 down(&adb_handler_sem);
533 write_lock_irq(&adb_handler_lock);
534 if (adb_handler[index].handler) {
535 while(adb_handler[index].busy) {
536 write_unlock_irq(&adb_handler_lock);
537 yield();
538 write_lock_irq(&adb_handler_lock);
540 ret = 0;
541 adb_handler[index].handler = NULL;
543 write_unlock_irq(&adb_handler_lock);
544 up(&adb_handler_sem);
545 return ret;
548 void
549 adb_input(unsigned char *buf, int nb, int autopoll)
551 int i, id;
552 static int dump_adb_input = 0;
553 unsigned long flags;
555 void (*handler)(unsigned char *, int, int);
557 /* We skip keystrokes and mouse moves when the sleep process
558 * has been started. We stop autopoll, but this is another security
560 if (adb_got_sleep)
561 return;
563 id = buf[0] >> 4;
564 if (dump_adb_input) {
565 printk(KERN_INFO "adb packet: ");
566 for (i = 0; i < nb; ++i)
567 printk(" %x", buf[i]);
568 printk(", id = %d\n", id);
570 write_lock_irqsave(&adb_handler_lock, flags);
571 handler = adb_handler[id].handler;
572 if (handler != NULL)
573 adb_handler[id].busy = 1;
574 write_unlock_irqrestore(&adb_handler_lock, flags);
575 if (handler != NULL) {
576 (*handler)(buf, nb, autopoll);
577 wmb();
578 adb_handler[id].busy = 0;
583 /* Try to change handler to new_id. Will return 1 if successful. */
584 static int try_handler_change(int address, int new_id)
586 struct adb_request req;
588 if (adb_handler[address].handler_id == new_id)
589 return 1;
590 adb_request(&req, NULL, ADBREQ_SYNC, 3,
591 ADB_WRITEREG(address, 3), address | 0x20, new_id);
592 adb_request(&req, NULL, ADBREQ_SYNC | ADBREQ_REPLY, 1,
593 ADB_READREG(address, 3));
594 if (req.reply_len < 2)
595 return 0;
596 if (req.reply[2] != new_id)
597 return 0;
598 adb_handler[address].handler_id = req.reply[2];
600 return 1;
604 adb_try_handler_change(int address, int new_id)
606 int ret;
608 down(&adb_handler_sem);
609 ret = try_handler_change(address, new_id);
610 up(&adb_handler_sem);
611 return ret;
615 adb_get_infos(int address, int *original_address, int *handler_id)
617 down(&adb_handler_sem);
618 *original_address = adb_handler[address].original_address;
619 *handler_id = adb_handler[address].handler_id;
620 up(&adb_handler_sem);
622 return (*original_address != 0);
627 * /dev/adb device driver.
630 #define ADB_MAJOR 56 /* major number for /dev/adb */
632 struct adbdev_state {
633 spinlock_t lock;
634 atomic_t n_pending;
635 struct adb_request *completed;
636 wait_queue_head_t wait_queue;
637 int inuse;
640 static void adb_write_done(struct adb_request *req)
642 struct adbdev_state *state = (struct adbdev_state *) req->arg;
643 unsigned long flags;
645 if (!req->complete) {
646 req->reply_len = 0;
647 req->complete = 1;
649 spin_lock_irqsave(&state->lock, flags);
650 atomic_dec(&state->n_pending);
651 if (!state->inuse) {
652 kfree(req);
653 if (atomic_read(&state->n_pending) == 0) {
654 spin_unlock_irqrestore(&state->lock, flags);
655 kfree(state);
656 return;
658 } else {
659 struct adb_request **ap = &state->completed;
660 while (*ap != NULL)
661 ap = &(*ap)->next;
662 req->next = NULL;
663 *ap = req;
664 wake_up_interruptible(&state->wait_queue);
666 spin_unlock_irqrestore(&state->lock, flags);
669 static int
670 do_adb_query(struct adb_request *req)
672 int ret = -EINVAL;
674 switch(req->data[1])
676 case ADB_QUERY_GETDEVINFO:
677 if (req->nbytes < 3)
678 break;
679 down(&adb_handler_sem);
680 req->reply[0] = adb_handler[req->data[2]].original_address;
681 req->reply[1] = adb_handler[req->data[2]].handler_id;
682 up(&adb_handler_sem);
683 req->complete = 1;
684 req->reply_len = 2;
685 adb_write_done(req);
686 ret = 0;
687 break;
689 return ret;
692 static int adb_open(struct inode *inode, struct file *file)
694 struct adbdev_state *state;
696 if (iminor(inode) > 0 || adb_controller == NULL)
697 return -ENXIO;
698 state = kmalloc(sizeof(struct adbdev_state), GFP_KERNEL);
699 if (state == 0)
700 return -ENOMEM;
701 file->private_data = state;
702 spin_lock_init(&state->lock);
703 atomic_set(&state->n_pending, 0);
704 state->completed = NULL;
705 init_waitqueue_head(&state->wait_queue);
706 state->inuse = 1;
708 return 0;
711 static int adb_release(struct inode *inode, struct file *file)
713 struct adbdev_state *state = file->private_data;
714 unsigned long flags;
716 lock_kernel();
717 if (state) {
718 file->private_data = NULL;
719 spin_lock_irqsave(&state->lock, flags);
720 if (atomic_read(&state->n_pending) == 0
721 && state->completed == NULL) {
722 spin_unlock_irqrestore(&state->lock, flags);
723 kfree(state);
724 } else {
725 state->inuse = 0;
726 spin_unlock_irqrestore(&state->lock, flags);
729 unlock_kernel();
730 return 0;
733 static ssize_t adb_read(struct file *file, char __user *buf,
734 size_t count, loff_t *ppos)
736 int ret = 0;
737 struct adbdev_state *state = file->private_data;
738 struct adb_request *req;
739 wait_queue_t wait = __WAITQUEUE_INITIALIZER(wait,current);
740 unsigned long flags;
742 if (count < 2)
743 return -EINVAL;
744 if (count > sizeof(req->reply))
745 count = sizeof(req->reply);
746 if (!access_ok(VERIFY_WRITE, buf, count))
747 return -EFAULT;
749 req = NULL;
750 spin_lock_irqsave(&state->lock, flags);
751 add_wait_queue(&state->wait_queue, &wait);
752 current->state = TASK_INTERRUPTIBLE;
754 for (;;) {
755 req = state->completed;
756 if (req != NULL)
757 state->completed = req->next;
758 else if (atomic_read(&state->n_pending) == 0)
759 ret = -EIO;
760 if (req != NULL || ret != 0)
761 break;
763 if (file->f_flags & O_NONBLOCK) {
764 ret = -EAGAIN;
765 break;
767 if (signal_pending(current)) {
768 ret = -ERESTARTSYS;
769 break;
771 spin_unlock_irqrestore(&state->lock, flags);
772 schedule();
773 spin_lock_irqsave(&state->lock, flags);
776 current->state = TASK_RUNNING;
777 remove_wait_queue(&state->wait_queue, &wait);
778 spin_unlock_irqrestore(&state->lock, flags);
780 if (ret)
781 return ret;
783 ret = req->reply_len;
784 if (ret > count)
785 ret = count;
786 if (ret > 0 && copy_to_user(buf, req->reply, ret))
787 ret = -EFAULT;
789 kfree(req);
790 return ret;
793 static ssize_t adb_write(struct file *file, const char __user *buf,
794 size_t count, loff_t *ppos)
796 int ret/*, i*/;
797 struct adbdev_state *state = file->private_data;
798 struct adb_request *req;
800 if (count < 2 || count > sizeof(req->data))
801 return -EINVAL;
802 if (adb_controller == NULL)
803 return -ENXIO;
804 if (!access_ok(VERIFY_READ, buf, count))
805 return -EFAULT;
807 req = kmalloc(sizeof(struct adb_request),
808 GFP_KERNEL);
809 if (req == NULL)
810 return -ENOMEM;
812 req->nbytes = count;
813 req->done = adb_write_done;
814 req->arg = (void *) state;
815 req->complete = 0;
817 ret = -EFAULT;
818 if (copy_from_user(req->data, buf, count))
819 goto out;
821 atomic_inc(&state->n_pending);
823 /* If a probe is in progress or we are sleeping, wait for it to complete */
824 down(&adb_probe_mutex);
826 /* Queries are special requests sent to the ADB driver itself */
827 if (req->data[0] == ADB_QUERY) {
828 if (count > 1)
829 ret = do_adb_query(req);
830 else
831 ret = -EINVAL;
832 up(&adb_probe_mutex);
834 /* Special case for ADB_BUSRESET request, all others are sent to
835 the controller */
836 else if ((req->data[0] == ADB_PACKET)&&(count > 1)
837 &&(req->data[1] == ADB_BUSRESET)) {
838 ret = do_adb_reset_bus();
839 up(&adb_probe_mutex);
840 atomic_dec(&state->n_pending);
841 if (ret == 0)
842 ret = count;
843 goto out;
844 } else {
845 req->reply_expected = ((req->data[1] & 0xc) == 0xc);
846 if (adb_controller && adb_controller->send_request)
847 ret = adb_controller->send_request(req, 0);
848 else
849 ret = -ENXIO;
850 up(&adb_probe_mutex);
853 if (ret != 0) {
854 atomic_dec(&state->n_pending);
855 goto out;
857 return count;
859 out:
860 kfree(req);
861 return ret;
864 static const struct file_operations adb_fops = {
865 .owner = THIS_MODULE,
866 .llseek = no_llseek,
867 .read = adb_read,
868 .write = adb_write,
869 .open = adb_open,
870 .release = adb_release,
873 static void
874 adbdev_init(void)
876 if (register_chrdev(ADB_MAJOR, "adb", &adb_fops)) {
877 printk(KERN_ERR "adb: unable to get major %d\n", ADB_MAJOR);
878 return;
881 adb_dev_class = class_create(THIS_MODULE, "adb");
882 if (IS_ERR(adb_dev_class))
883 return;
884 class_device_create(adb_dev_class, NULL, MKDEV(ADB_MAJOR, 0), NULL, "adb");