Lines Matching refs:gameport

43 static void gameport_add_port(struct gameport *gameport);
45 static void gameport_reconnect_port(struct gameport *gameport);
46 static void gameport_disconnect_port(struct gameport *gameport);
77 static int gameport_measure_speed(struct gameport *gameport) in gameport_measure_speed() argument
83 if (gameport_open(gameport, NULL, GAMEPORT_MODE_RAW)) in gameport_measure_speed()
92 gameport_read(gameport); in gameport_measure_speed()
102 gameport_close(gameport); in gameport_measure_speed()
109 static int old_gameport_measure_speed(struct gameport *gameport) in old_gameport_measure_speed() argument
116 if (gameport_open(gameport, NULL, GAMEPORT_MODE_RAW)) in old_gameport_measure_speed()
124 for (t = 0; t < 50; t++) gameport_read(gameport); in old_gameport_measure_speed()
132 gameport_close(gameport); in old_gameport_measure_speed()
140 if (gameport_open(gameport, NULL, GAMEPORT_MODE_RAW)) in old_gameport_measure_speed()
148 for (t = 0; t < 50; t++) gameport_read(gameport); in old_gameport_measure_speed()
155 gameport_close(gameport); in old_gameport_measure_speed()
163 if (gameport_open(gameport, NULL, GAMEPORT_MODE_RAW)) in old_gameport_measure_speed()
167 j = jiffies; while (j == jiffies) { t++; gameport_read(gameport); } in old_gameport_measure_speed()
169 gameport_close(gameport); in old_gameport_measure_speed()
175 void gameport_start_polling(struct gameport *gameport) in gameport_start_polling() argument
177 spin_lock(&gameport->timer_lock); in gameport_start_polling()
179 if (!gameport->poll_cnt++) { in gameport_start_polling()
180 BUG_ON(!gameport->poll_handler); in gameport_start_polling()
181 BUG_ON(!gameport->poll_interval); in gameport_start_polling()
182 mod_timer(&gameport->poll_timer, jiffies + msecs_to_jiffies(gameport->poll_interval)); in gameport_start_polling()
185 spin_unlock(&gameport->timer_lock); in gameport_start_polling()
189 void gameport_stop_polling(struct gameport *gameport) in gameport_stop_polling() argument
191 spin_lock(&gameport->timer_lock); in gameport_stop_polling()
193 if (!--gameport->poll_cnt) in gameport_stop_polling()
194 del_timer(&gameport->poll_timer); in gameport_stop_polling()
196 spin_unlock(&gameport->timer_lock); in gameport_stop_polling()
202 struct gameport *gameport = from_timer(gameport, t, poll_timer); in gameport_run_poll_handler() local
204 gameport->poll_handler(gameport); in gameport_run_poll_handler()
205 if (gameport->poll_cnt) in gameport_run_poll_handler()
206 mod_timer(&gameport->poll_timer, jiffies + msecs_to_jiffies(gameport->poll_interval)); in gameport_run_poll_handler()
213 static int gameport_bind_driver(struct gameport *gameport, struct gameport_driver *drv) in gameport_bind_driver() argument
217 gameport->dev.driver = &drv->driver; in gameport_bind_driver()
218 if (drv->connect(gameport, drv)) { in gameport_bind_driver()
219 gameport->dev.driver = NULL; in gameport_bind_driver()
223 error = device_bind_driver(&gameport->dev); in gameport_bind_driver()
225 dev_warn(&gameport->dev, in gameport_bind_driver()
227 gameport->phys, gameport->name, in gameport_bind_driver()
229 drv->disconnect(gameport); in gameport_bind_driver()
230 gameport->dev.driver = NULL; in gameport_bind_driver()
237 static void gameport_find_driver(struct gameport *gameport) in gameport_find_driver() argument
241 error = device_attach(&gameport->dev); in gameport_find_driver()
243 dev_warn(&gameport->dev, in gameport_find_driver()
245 gameport->phys, gameport->name, error); in gameport_find_driver()
431 static struct gameport *gameport_get_pending_child(struct gameport *parent) in gameport_get_pending_child()
434 struct gameport *gameport, *child = NULL; in gameport_get_pending_child() local
441 gameport = event->object; in gameport_get_pending_child()
442 if (gameport->parent == parent) { in gameport_get_pending_child()
443 child = gameport; in gameport_get_pending_child()
459 struct gameport *gameport = to_gameport_port(dev); in gameport_description_show() local
461 return sprintf(buf, "%s\n", gameport->name); in gameport_description_show()
467 struct gameport *gameport = to_gameport_port(dev); in drvctl_store() local
476 gameport_disconnect_port(gameport); in drvctl_store()
478 gameport_reconnect_port(gameport); in drvctl_store()
480 gameport_disconnect_port(gameport); in drvctl_store()
481 gameport_find_driver(gameport); in drvctl_store()
483 gameport_disconnect_port(gameport); in drvctl_store()
484 error = gameport_bind_driver(gameport, to_gameport_driver(drv)); in drvctl_store()
504 struct gameport *gameport = to_gameport_port(dev); in gameport_release_port() local
506 kfree(gameport); in gameport_release_port()
510 void gameport_set_phys(struct gameport *gameport, const char *fmt, ...) in gameport_set_phys() argument
515 vsnprintf(gameport->phys, sizeof(gameport->phys), fmt, args); in gameport_set_phys()
520 static void gameport_default_trigger(struct gameport *gameport) in gameport_default_trigger() argument
523 outb(0xff, gameport->io); in gameport_default_trigger()
527 static unsigned char gameport_default_read(struct gameport *gameport) in gameport_default_read() argument
530 return inb(gameport->io); in gameport_default_read()
536 static void gameport_setup_default_handlers(struct gameport *gameport) in gameport_setup_default_handlers() argument
538 if ((!gameport->trigger || !gameport->read) && in gameport_setup_default_handlers()
540 dev_err(&gameport->dev, in gameport_setup_default_handlers()
542 gameport->phys, gameport->name); in gameport_setup_default_handlers()
544 if (!gameport->trigger) in gameport_setup_default_handlers()
545 gameport->trigger = gameport_default_trigger; in gameport_setup_default_handlers()
546 if (!gameport->read) in gameport_setup_default_handlers()
547 gameport->read = gameport_default_read; in gameport_setup_default_handlers()
553 static void gameport_init_port(struct gameport *gameport) in gameport_init_port() argument
559 mutex_init(&gameport->drv_mutex); in gameport_init_port()
560 device_initialize(&gameport->dev); in gameport_init_port()
561 dev_set_name(&gameport->dev, "gameport%lu", in gameport_init_port()
563 gameport->dev.bus = &gameport_bus; in gameport_init_port()
564 gameport->dev.release = gameport_release_port; in gameport_init_port()
565 if (gameport->parent) in gameport_init_port()
566 gameport->dev.parent = &gameport->parent->dev; in gameport_init_port()
568 gameport_setup_default_handlers(gameport); in gameport_init_port()
569 INIT_LIST_HEAD(&gameport->node); in gameport_init_port()
570 spin_lock_init(&gameport->timer_lock); in gameport_init_port()
571 timer_setup(&gameport->poll_timer, gameport_run_poll_handler, 0); in gameport_init_port()
578 static void gameport_add_port(struct gameport *gameport) in gameport_add_port() argument
582 if (gameport->parent) in gameport_add_port()
583 gameport->parent->child = gameport; in gameport_add_port()
585 gameport->speed = use_ktime ? in gameport_add_port()
586 gameport_measure_speed(gameport) : in gameport_add_port()
587 old_gameport_measure_speed(gameport); in gameport_add_port()
589 list_add_tail(&gameport->node, &gameport_list); in gameport_add_port()
591 if (gameport->io) in gameport_add_port()
592 dev_info(&gameport->dev, "%s is %s, io %#x, speed %dkHz\n", in gameport_add_port()
593 gameport->name, gameport->phys, gameport->io, gameport->speed); in gameport_add_port()
595 dev_info(&gameport->dev, "%s is %s, speed %dkHz\n", in gameport_add_port()
596 gameport->name, gameport->phys, gameport->speed); in gameport_add_port()
598 error = device_add(&gameport->dev); in gameport_add_port()
600 dev_err(&gameport->dev, in gameport_add_port()
602 gameport->phys, gameport->name, error); in gameport_add_port()
609 static void gameport_destroy_port(struct gameport *gameport) in gameport_destroy_port() argument
611 struct gameport *child; in gameport_destroy_port()
613 child = gameport_get_pending_child(gameport); in gameport_destroy_port()
619 if (gameport->parent) { in gameport_destroy_port()
620 gameport->parent->child = NULL; in gameport_destroy_port()
621 gameport->parent = NULL; in gameport_destroy_port()
624 if (device_is_registered(&gameport->dev)) in gameport_destroy_port()
625 device_del(&gameport->dev); in gameport_destroy_port()
627 list_del_init(&gameport->node); in gameport_destroy_port()
629 gameport_remove_pending_events(gameport); in gameport_destroy_port()
630 put_device(&gameport->dev); in gameport_destroy_port()
636 static void gameport_reconnect_port(struct gameport *gameport) in gameport_reconnect_port() argument
639 if (!gameport->drv || !gameport->drv->reconnect || gameport->drv->reconnect(gameport)) { in gameport_reconnect_port()
640 gameport_disconnect_port(gameport); in gameport_reconnect_port()
641 gameport_find_driver(gameport); in gameport_reconnect_port()
645 gameport = gameport->child; in gameport_reconnect_port()
646 } while (gameport); in gameport_reconnect_port()
653 static void gameport_disconnect_port(struct gameport *gameport) in gameport_disconnect_port() argument
655 struct gameport *s, *parent; in gameport_disconnect_port()
657 if (gameport->child) { in gameport_disconnect_port()
663 for (s = gameport; s->child; s = s->child) in gameport_disconnect_port()
671 } while ((s = parent) != gameport); in gameport_disconnect_port()
677 device_release_driver(&gameport->dev); in gameport_disconnect_port()
684 void __gameport_register_port(struct gameport *gameport, struct module *owner) in __gameport_register_port() argument
686 gameport_init_port(gameport); in __gameport_register_port()
687 gameport_queue_event(gameport, owner, GAMEPORT_REGISTER_PORT); in __gameport_register_port()
694 void gameport_unregister_port(struct gameport *gameport) in gameport_unregister_port() argument
697 gameport_disconnect_port(gameport); in gameport_unregister_port()
698 gameport_destroy_port(gameport); in gameport_unregister_port()
723 struct gameport *gameport = to_gameport_port(dev); in gameport_driver_probe() local
726 drv->connect(gameport, drv); in gameport_driver_probe()
727 return gameport->drv ? 0 : -ENODEV; in gameport_driver_probe()
732 struct gameport *gameport = to_gameport_port(dev); in gameport_driver_remove() local
735 drv->disconnect(gameport); in gameport_driver_remove()
786 struct gameport *gameport; in gameport_unregister_driver() local
794 list_for_each_entry(gameport, &gameport_list, node) { in gameport_unregister_driver()
795 if (gameport->drv == drv) { in gameport_unregister_driver()
796 gameport_disconnect_port(gameport); in gameport_unregister_driver()
797 gameport_find_driver(gameport); in gameport_unregister_driver()
825 static void gameport_set_drv(struct gameport *gameport, struct gameport_driver *drv) in gameport_set_drv() argument
827 mutex_lock(&gameport->drv_mutex); in gameport_set_drv()
828 gameport->drv = drv; in gameport_set_drv()
829 mutex_unlock(&gameport->drv_mutex); in gameport_set_drv()
832 int gameport_open(struct gameport *gameport, struct gameport_driver *drv, int mode) in gameport_open() argument
834 if (gameport->open) { in gameport_open()
835 if (gameport->open(gameport, mode)) { in gameport_open()
843 gameport_set_drv(gameport, drv); in gameport_open()
848 void gameport_close(struct gameport *gameport) in gameport_close() argument
850 del_timer_sync(&gameport->poll_timer); in gameport_close()
851 gameport->poll_handler = NULL; in gameport_close()
852 gameport->poll_interval = 0; in gameport_close()
853 gameport_set_drv(gameport, NULL); in gameport_close()
854 if (gameport->close) in gameport_close()
855 gameport->close(gameport); in gameport_close()