Skip to content

Commit f11f1a9

Browse files
committed
Input: gameport - provide default trigger() and read()
Instead of constantly checking pointer(s) for non-NULL-ness provide default implementations of trigger() and read() and instantiate them during pore registration if driver-specific versions were not provided. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent d9f12a3 commit f11f1a9

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

drivers/input/gameport/gameport.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <linux/stddef.h>
1313
#include <linux/module.h>
14+
#include <linux/io.h>
1415
#include <linux/ioport.h>
1516
#include <linux/init.h>
1617
#include <linux/gameport.h>
@@ -21,8 +22,6 @@
2122
#include <linux/mutex.h>
2223
#include <linux/timekeeping.h>
2324

24-
/*#include <asm/io.h>*/
25-
2625
MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");
2726
MODULE_DESCRIPTION("Generic gameport layer");
2827
MODULE_LICENSE("GPL");
@@ -518,6 +517,16 @@ void gameport_set_phys(struct gameport *gameport, const char *fmt, ...)
518517
}
519518
EXPORT_SYMBOL(gameport_set_phys);
520519

520+
static void gameport_default_trigger(struct gameport *gameport)
521+
{
522+
outb(0xff, gameport->io);
523+
}
524+
525+
static unsigned char gameport_default_read(struct gameport *gameport)
526+
{
527+
return inb(gameport->io);
528+
}
529+
521530
/*
522531
* Prepare gameport port for registration.
523532
*/
@@ -536,6 +545,11 @@ static void gameport_init_port(struct gameport *gameport)
536545
if (gameport->parent)
537546
gameport->dev.parent = &gameport->parent->dev;
538547

548+
if (!gameport->trigger)
549+
gameport->trigger = gameport_default_trigger;
550+
if (!gameport->read)
551+
gameport->read = gameport_default_read;
552+
539553
INIT_LIST_HEAD(&gameport->node);
540554
spin_lock_init(&gameport->timer_lock);
541555
timer_setup(&gameport->poll_timer, gameport_run_poll_handler, 0);

include/linux/gameport.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#ifndef _GAMEPORT_H
66
#define _GAMEPORT_H
77

8-
#include <asm/io.h>
98
#include <linux/types.h>
109
#include <linux/list.h>
1110
#include <linux/mutex.h>
@@ -165,18 +164,12 @@ void gameport_unregister_driver(struct gameport_driver *drv);
165164

166165
static inline void gameport_trigger(struct gameport *gameport)
167166
{
168-
if (gameport->trigger)
169-
gameport->trigger(gameport);
170-
else
171-
outb(0xff, gameport->io);
167+
gameport->trigger(gameport);
172168
}
173169

174170
static inline unsigned char gameport_read(struct gameport *gameport)
175171
{
176-
if (gameport->read)
177-
return gameport->read(gameport);
178-
else
179-
return inb(gameport->io);
172+
return gameport->read(gameport);
180173
}
181174

182175
static inline int gameport_cooked_read(struct gameport *gameport, int *axes, int *buttons)

0 commit comments

Comments
 (0)