Skip to contentSkip to conversation

Convert gameport to driver model/sysfs

PATCH In review Dmitry Torokhov 2 participants 13 messages Feb 11, 2005

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Convert gameport to driver model/sysfs

Hi,

This series of patches adds a new "gameport" bus to the driver model. It is implemented very similarly to "serio" bus and also allows individual drivers to be manually bound/disconnected from a port by manipulating port's "drvctl" attribute.

01-gameport-renames1.patch
- rename gameport->driver to gameport->port_data in preparation to sysfs integration to avoid confusion with real drivers.

02-gameport-renames2.patch
- more renames in gameport in preparations to sysfs integration, gameport_dev renamed to gameport_driver, gameport_[un]register_device renamed to gameport_[un]register_driver

03-gameport-connect-mandatory.patch
- make connect and disconnect mandatory as these call gameport_open and gameport_close which actually bind driver and port together.

04-gameport-dynalloc-prepare.patch
- sysfs/kobjects requires objects be allocated synamically. Prepare to dynamic gameport allocation, create gameport_allocate_port and gameport_free_port; dynamically allocated ports are freed by core upon release. Also add gameport_set_name and gameport_set_phys to ease transition.

05-gameport-dynalloc-input.patch
- convert drivers in input/gameport to dynamic gameport allocation.

06-gameport-dynalloc-sound-oss.patch
- convert drivers in sound/oss to dynamic gameport allocation.

07-gameport-dynalloc-sound-alsa.patch
- convert drivers in sound/pci to dynamic gameport allocation.

08-gameport-drivers-sysfs.patch
- add "gameport" bus and have joystick gameport drivers register themselves on this bus.

09-gameport-devices-sysfs.patch
- complete gameport sysfs integration. Gameports are registered on the "gameport" bus.

10-gameport-drvdata.patch
- Get rid of gameport->private, use driver-specific data in device structure, access through gameport_get/set_drvdata helpers.

The changes can also be pulled from my tree (which has Vojtech's input tree as a parent):

bk pull bk://dtor.bkbits.net/input

I am CC-ing ALSA list as the changes touch quite a few sound drivers.

Comments/testing is appreciated.

Signature · 8 lines
Dmitry


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
#1 lore raw

PATCH 1/10 Gameport: rename driver to port_data

===================================================================

[email protected], 2005-02-11 01:09:43-05:00, [email protected]
Input: rename gameport->driver to gameport->port_data in preparation
to sysfs integration.

 drivers/input/gameport/lightning.c |    8 ++++----
 drivers/input/gameport/vortex.c    |   10 +++++-----
 drivers/input/joystick/a3d.c       |    8 ++++----
 include/linux/gameport.h           |    4 ++--
 sound/oss/trident.c                |   10 +++++-----
 sound/pci/au88x0/au88x0_game.c     |   15 +++++++--------
 6 files changed, 27 insertions(+), 28 deletions(-)

===================================================================

drivers/input/gameport/lightning.c +4 -4
diff -Nru a/drivers/input/gameport/lightning.c b/drivers/input/gameport/lightning.c
@@ -79,7 +79,7 @@
 
 static int l4_cooked_read(struct gameport *gameport, int *axes, int *buttons)
 {
-	struct l4 *l4 = gameport->driver;
+	struct l4 *l4 = gameport->port_data;
 	unsigned char status;
 	int i, result = -1;
 
@@ -112,7 +112,7 @@
 
 static int l4_open(struct gameport *gameport, int mode)
 {
-	struct l4 *l4 = gameport->driver;
+	struct l4 *l4 = gameport->port_data;
         if (l4->port != 0 && mode != GAMEPORT_MODE_COOKED)
 		return -1;
 	outb(L4_SELECT_ANALOG, L4_PORT);
@@ -190,7 +190,7 @@
 {
 	int i, t;
 	int cal[4];
-	struct l4 *l4 = gameport->driver;
+	struct l4 *l4 = gameport->port_data;
 
 	if (l4_getcal(l4->port, cal))
 		return -1;
@@ -252,7 +252,7 @@
 			sprintf(l4->phys, "isa%04x/gameport%d", L4_PORT, 4 * i + j);
 
 			gameport = &l4->gameport;
-			gameport->driver = l4;
+			gameport->port_data = l4;
 			gameport->open = l4_open;
 			gameport->cooked_read = l4_cooked_read;
 			gameport->calibrate = l4_calibrate;
drivers/input/gameport/vortex.c +5 -5
diff -Nru a/drivers/input/gameport/vortex.c b/drivers/input/gameport/vortex.c
@@ -62,19 +62,19 @@
 
 static unsigned char vortex_read(struct gameport *gameport)
 {
-	struct vortex *vortex = gameport->driver;
+	struct vortex *vortex = gameport->port_data;
 	return readb(vortex->io + VORTEX_LEG);
 }
 
 static void vortex_trigger(struct gameport *gameport)
 {
-	struct vortex *vortex = gameport->driver;
+	struct vortex *vortex = gameport->port_data;
 	writeb(0xff, vortex->io + VORTEX_LEG);
 }
 
 static int vortex_cooked_read(struct gameport *gameport, int *axes, int *buttons)
 {
-	struct vortex *vortex = gameport->driver;
+	struct vortex *vortex = gameport->port_data;
 	int i;
 
 	*buttons = (~readb(vortex->base + VORTEX_LEG) >> 4) & 0xf;
@@ -89,7 +89,7 @@
 
 static int vortex_open(struct gameport *gameport, int mode)
 {
-	struct vortex *vortex = gameport->driver;
+	struct vortex *vortex = gameport->port_data;
 
 	switch (mode) {
 		case GAMEPORT_MODE_COOKED:
@@ -120,7 +120,7 @@
 
 	pci_set_drvdata(dev, vortex);
 
-	vortex->gameport.driver = vortex;
+	vortex->gameport.port_data = vortex;
 	vortex->gameport.fuzz = 64;
 
 	vortex->gameport.read = vortex_read;
drivers/input/joystick/a3d.c +4 -4
diff -Nru a/drivers/input/joystick/a3d.c b/drivers/input/joystick/a3d.c
@@ -197,7 +197,7 @@
 
 static int a3d_adc_cooked_read(struct gameport *gameport, int *axes, int *buttons)
 {
-	struct a3d *a3d = gameport->driver;
+	struct a3d *a3d = gameport->port_data;
 	int i;
 	for (i = 0; i < 4; i++)
 		axes[i] = (a3d->axes[i] < 254) ? a3d->axes[i] : -1;
@@ -212,7 +212,7 @@
 
 static int a3d_adc_open(struct gameport *gameport, int mode)
 {
-	struct a3d *a3d = gameport->driver;
+	struct a3d *a3d = gameport->port_data;
 	if (mode != GAMEPORT_MODE_COOKED)
 		return -1;
 	if (!a3d->used++)
@@ -226,7 +226,7 @@
 
 static void a3d_adc_close(struct gameport *gameport)
 {
-	struct a3d *a3d = gameport->driver;
+	struct a3d *a3d = gameport->port_data;
 	if (!--a3d->used)
 		del_timer(&a3d->timer);
 }
@@ -336,7 +336,7 @@
 		a3d->dev.relbit[0] |= BIT(REL_X) | BIT(REL_Y);
 		a3d->dev.keybit[LONG(BTN_MOUSE)] |= BIT(BTN_RIGHT) | BIT(BTN_LEFT) | BIT(BTN_MIDDLE);
 
-		a3d->adc.driver = a3d;
+		a3d->adc.port_data = a3d;
 		a3d->adc.open = a3d_adc_open;
 		a3d->adc.close = a3d_adc_close;
 		a3d->adc.cooked_read = a3d_adc_cooked_read;
include/linux/gameport.h +2 -2
diff -Nru a/include/linux/gameport.h b/include/linux/gameport.h
@@ -17,8 +17,8 @@
 
 struct gameport {
 
-	void *private;	/* Private pointer for joystick drivers */
-	void *driver;	/* Private pointer for gameport drivers */
+	void *private;		/* Private pointer for joystick drivers */
+	void *port_data;	/* Private pointer for gameport drivers */
 	char *name;
 	char *phys;
 
sound/oss/trident.c +5 -5
diff -Nru a/sound/oss/trident.c b/sound/oss/trident.c
@@ -4257,21 +4257,21 @@
 static unsigned char
 trident_game_read(struct gameport *gameport)
 {
-	struct trident_card *card = gameport->driver;
+	struct trident_card *card = gameport->port_data;
 	return inb(TRID_REG(card, T4D_GAME_LEG));
 }
 
 static void
 trident_game_trigger(struct gameport *gameport)
 {
-	struct trident_card *card = gameport->driver;
+	struct trident_card *card = gameport->port_data;
 	outb(0xff, TRID_REG(card, T4D_GAME_LEG));
 }
 
 static int
 trident_game_cooked_read(struct gameport *gameport, int *axes, int *buttons)
 {
-	struct trident_card *card = gameport->driver;
+	struct trident_card *card = gameport->port_data;
 	int i;
 
 	*buttons = (~inb(TRID_REG(card, T4D_GAME_LEG)) >> 4) & 0xf;
@@ -4288,7 +4288,7 @@
 static int
 trident_game_open(struct gameport *gameport, int mode)
 {
-	struct trident_card *card = gameport->driver;
+	struct trident_card *card = gameport->port_data;
 
 	switch (mode) {
 	case GAMEPORT_MODE_COOKED:
@@ -4368,7 +4368,7 @@
 	card->banks[BANK_B].addresses = &bank_b_addrs;
 	card->banks[BANK_B].bitmap = 0UL;
 
-	card->gameport.driver = card;
+	card->gameport.port_data = card;
 	card->gameport.fuzz = 64;
 	card->gameport.read = trident_game_read;
 	card->gameport.trigger = trident_game_trigger;
sound/pci/au88x0/au88x0_game.c +7 -8
diff -Nru a/sound/pci/au88x0/au88x0_game.c b/sound/pci/au88x0/au88x0_game.c
@@ -44,20 +44,20 @@
 
 static unsigned char vortex_game_read(struct gameport *gameport)
 {
-	vortex_t *vortex = gameport->driver;
+	vortex_t *vortex = gameport->port_data;
 	return hwread(vortex->mmio, VORTEX_GAME_LEGACY);
 }
 
 static void vortex_game_trigger(struct gameport *gameport)
 {
-	vortex_t *vortex = gameport->driver;
+	vortex_t *vortex = gameport->port_data;
 	hwwrite(vortex->mmio, VORTEX_GAME_LEGACY, 0xff);
 }
 
 static int
 vortex_game_cooked_read(struct gameport *gameport, int *axes, int *buttons)
 {
-	vortex_t *vortex = gameport->driver;
+	vortex_t *vortex = gameport->port_data;
 	int i;
 
 	*buttons = (~hwread(vortex->mmio, VORTEX_GAME_LEGACY) >> 4) & 0xf;
@@ -73,7 +73,7 @@
 
 static int vortex_game_open(struct gameport *gameport, int mode)
 {
-	vortex_t *vortex = gameport->driver;
+	vortex_t *vortex = gameport->port_data;
 
 	switch (mode) {
 	case GAMEPORT_MODE_COOKED:
@@ -96,11 +96,10 @@
 
 static int vortex_gameport_register(vortex_t * vortex)
 {
-	if ((vortex->gameport = kcalloc(1, sizeof(struct gameport), GFP_KERNEL)) == NULL) {
+	if ((vortex->gameport = kcalloc(1, sizeof(struct gameport), GFP_KERNEL)) == NULL)
 		return -1;
-	};
-	
-	vortex->gameport->driver = vortex;
+
+	vortex->gameport->port_data = vortex;
 	vortex->gameport->fuzz = 64;
 
 	vortex->gameport->read = vortex_game_read;

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click

#2 lore raw

PATCH 2/10 Gameport: rename gameport_dev to gameport_driver

===================================================================

[email protected], 2005-02-11 01:09:59-05:00, [email protected]
Input: more renames in gameport in preparations to sysfs integration
- gameport_dev -> gameport_driver
- gameport_[un]register_device -> gameport_[un]register_driver

 drivers/input/gameport/gameport.c   |   52 ++++++++++++++++++------------------
 drivers/input/joystick/a3d.c        |   10 +++---
 drivers/input/joystick/adi.c        |   10 +++---
 drivers/input/joystick/analog.c     |   18 ++++++------
 drivers/input/joystick/cobra.c      |   10 +++---
 drivers/input/joystick/gf2k.c       |   10 +++---
 drivers/input/joystick/grip.c       |   10 +++---
 drivers/input/joystick/grip_mp.c    |   10 +++---
 drivers/input/joystick/guillemot.c  |   10 +++---
 drivers/input/joystick/interact.c   |   10 +++---
 drivers/input/joystick/joydump.c    |   12 ++++----
 drivers/input/joystick/sidewinder.c |   10 +++---
 drivers/input/joystick/tmdc.c       |   10 +++---
 include/linux/gameport.h            |   12 ++++----
 14 files changed, 97 insertions(+), 97 deletions(-)

===================================================================

drivers/input/gameport/gameport.c +26 -26
diff -Nru a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
@@ -25,15 +25,15 @@
 
 EXPORT_SYMBOL(gameport_register_port);
 EXPORT_SYMBOL(gameport_unregister_port);
-EXPORT_SYMBOL(gameport_register_device);
-EXPORT_SYMBOL(gameport_unregister_device);
+EXPORT_SYMBOL(gameport_register_driver);
+EXPORT_SYMBOL(gameport_unregister_driver);
 EXPORT_SYMBOL(gameport_open);
 EXPORT_SYMBOL(gameport_close);
 EXPORT_SYMBOL(gameport_rescan);
 EXPORT_SYMBOL(gameport_cooked_read);
 
 static LIST_HEAD(gameport_list);
-static LIST_HEAD(gameport_dev_list);
+static LIST_HEAD(gameport_driver_list);
 
 #ifdef __i386__
 
@@ -100,61 +100,61 @@
 #endif
 }
 
-static void gameport_find_dev(struct gameport *gameport)
+static void gameport_find_driver(struct gameport *gameport)
 {
-        struct gameport_dev *dev;
+        struct gameport_driver *drv;
 
-        list_for_each_entry(dev, &gameport_dev_list, node) {
-		if (gameport->dev)
+        list_for_each_entry(drv, &gameport_driver_list, node) {
+		if (gameport->drv)
 			break;
-		if (dev->connect)
-                	dev->connect(gameport, dev);
+		if (drv->connect)
+                	drv->connect(gameport, drv);
         }
 }
 
 void gameport_rescan(struct gameport *gameport)
 {
 	gameport_close(gameport);
-	gameport_find_dev(gameport);
+	gameport_find_driver(gameport);
 }
 
 void gameport_register_port(struct gameport *gameport)
 {
 	list_add_tail(&gameport->node, &gameport_list);
 	gameport->speed = gameport_measure_speed(gameport);
-	gameport_find_dev(gameport);
+	gameport_find_driver(gameport);
 }
 
 void gameport_unregister_port(struct gameport *gameport)
 {
 	list_del_init(&gameport->node);
-	if (gameport->dev && gameport->dev->disconnect)
-		gameport->dev->disconnect(gameport);
+	if (gameport->drv && gameport->drv->disconnect)
+		gameport->drv->disconnect(gameport);
 }
 
-void gameport_register_device(struct gameport_dev *dev)
+void gameport_register_driver(struct gameport_driver *drv)
 {
 	struct gameport *gameport;
 
-	list_add_tail(&dev->node, &gameport_dev_list);
+	list_add_tail(&drv->node, &gameport_driver_list);
 	list_for_each_entry(gameport, &gameport_list, node)
-		if (!gameport->dev && dev->connect)
-			dev->connect(gameport, dev);
+		if (!gameport->drv && drv->connect)
+			drv->connect(gameport, drv);
 }
 
-void gameport_unregister_device(struct gameport_dev *dev)
+void gameport_unregister_driver(struct gameport_driver *drv)
 {
 	struct gameport *gameport;
 
-	list_del_init(&dev->node);
+	list_del_init(&drv->node);
 	list_for_each_entry(gameport, &gameport_list, node) {
-		if (gameport->dev == dev && dev->disconnect)
-			dev->disconnect(gameport);
-		gameport_find_dev(gameport);
+		if (gameport->drv == drv && drv->disconnect)
+			drv->disconnect(gameport);
+		gameport_find_driver(gameport);
 	}
 }
 
-int gameport_open(struct gameport *gameport, struct gameport_dev *dev, int mode)
+int gameport_open(struct gameport *gameport, struct gameport_driver *drv, int mode)
 {
 	if (gameport->open) {
 		if (gameport->open(gameport, mode))
@@ -164,17 +164,17 @@
 			return -1;
 	}
 
-	if (gameport->dev)
+	if (gameport->drv)
 		return -1;
 
-	gameport->dev = dev;
+	gameport->drv = drv;
 
 	return 0;
 }
 
 void gameport_close(struct gameport *gameport)
 {
-	gameport->dev = NULL;
+	gameport->drv = NULL;
 	if (gameport->close)
 		gameport->close(gameport);
 }
drivers/input/joystick/a3d.c +5 -5
diff -Nru a/drivers/input/joystick/a3d.c b/drivers/input/joystick/a3d.c
@@ -258,7 +258,7 @@
  * a3d_connect() probes for A3D joysticks.
  */
 
-static void a3d_connect(struct gameport *gameport, struct gameport_dev *dev)
+static void a3d_connect(struct gameport *gameport, struct gameport_driver *drv)
 {
 	struct a3d *a3d;
 	unsigned char data[A3D_MAX_LENGTH];
@@ -275,7 +275,7 @@
 	a3d->timer.data = (long) a3d;
 	a3d->timer.function = a3d_timer;
 
-	if (gameport_open(gameport, dev, GAMEPORT_MODE_RAW))
+	if (gameport_open(gameport, drv, GAMEPORT_MODE_RAW))
 		goto fail1;
 
 	i = a3d_read_packet(gameport, A3D_MAX_LENGTH, data);
@@ -385,20 +385,20 @@
 	kfree(a3d);
 }
 
-static struct gameport_dev a3d_dev = {
+static struct gameport_driver a3d_drv = {
 	.connect =	a3d_connect,
 	.disconnect =	a3d_disconnect,
 };
 
 static int __init a3d_init(void)
 {
-	gameport_register_device(&a3d_dev);
+	gameport_register_driver(&a3d_drv);
 	return 0;
 }
 
 static void __exit a3d_exit(void)
 {
-	gameport_unregister_device(&a3d_dev);
+	gameport_unregister_driver(&a3d_drv);
 }
 
 module_init(a3d_init);
drivers/input/joystick/adi.c +5 -5
diff -Nru a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
@@ -475,7 +475,7 @@
  * adi_connect() probes for Logitech ADI joysticks.
  */
 
-static void adi_connect(struct gameport *gameport, struct gameport_dev *dev)
+static void adi_connect(struct gameport *gameport, struct gameport_driver *drv)
 {
 	struct adi_port *port;
 	int i;
@@ -491,7 +491,7 @@
 	port->timer.data = (long) port;
 	port->timer.function = adi_timer;
 
-	if (gameport_open(gameport, dev, GAMEPORT_MODE_RAW)) {
+	if (gameport_open(gameport, drv, GAMEPORT_MODE_RAW)) {
 		kfree(port);
 		return;
 	}
@@ -544,20 +544,20 @@
  * The gameport device structure.
  */
 
-static struct gameport_dev adi_dev = {
+static struct gameport_driver adi_drv = {
 	.connect =	adi_connect,
 	.disconnect =	adi_disconnect,
 };
 
 static int __init adi_init(void)
 {
-	gameport_register_device(&adi_dev);
+	gameport_register_driver(&adi_drv);
 	return 0;
 }
 
 static void __exit adi_exit(void)
 {
-	gameport_unregister_device(&adi_dev);
+	gameport_unregister_driver(&adi_drv);
 }
 
 module_init(adi_init);
drivers/input/joystick/analog.c +9 -9
diff -Nru a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c
@@ -587,7 +587,7 @@
 	return -!(analog[0].mask || analog[1].mask);
 }
 
-static int analog_init_port(struct gameport *gameport, struct gameport_dev *dev, struct analog_port *port)
+static int analog_init_port(struct gameport *gameport, struct gameport_driver *drv, struct analog_port *port)
 {
 	int i, t, u, v;
 
@@ -597,7 +597,7 @@
 	port->timer.data = (long) port;
 	port->timer.function = analog_timer;
 
-	if (!gameport_open(gameport, dev, GAMEPORT_MODE_RAW)) {
+	if (!gameport_open(gameport, drv, GAMEPORT_MODE_RAW)) {
 
 		analog_calibrate_timer(port);
 
@@ -632,7 +632,7 @@
 		gameport_close(gameport);
 	}
 
-	if (!gameport_open(gameport, dev, GAMEPORT_MODE_COOKED)) {
+	if (!gameport_open(gameport, drv, GAMEPORT_MODE_COOKED)) {
 
 		for (i = 0; i < ANALOG_INIT_RETRIES; i++)
 			if (!gameport_cooked_read(gameport, port->axes, &port->buttons))
@@ -645,13 +645,13 @@
 		return 0;
 	}
 
-	if (!gameport_open(gameport, dev, GAMEPORT_MODE_RAW))
+	if (!gameport_open(gameport, drv, GAMEPORT_MODE_RAW))
 		return 0;
 
 	return -1;
 }
 
-static void analog_connect(struct gameport *gameport, struct gameport_dev *dev)
+static void analog_connect(struct gameport *gameport, struct gameport_driver *drv)
 {
 	struct analog_port *port;
 	int i;
@@ -660,7 +660,7 @@
 		return;
 	memset(port, 0, sizeof(struct analog_port));
 
-	if (analog_init_port(gameport, dev, port)) {
+	if (analog_init_port(gameport, drv, port)) {
 		kfree(port);
 		return;
 	}
@@ -741,7 +741,7 @@
  * The gameport device structure.
  */
 
-static struct gameport_dev analog_dev = {
+static struct gameport_driver analog_drv = {
 	.connect =	analog_connect,
 	.disconnect =	analog_disconnect,
 };
@@ -749,13 +749,13 @@
 static int __init analog_init(void)
 {
 	analog_parse_options();
-	gameport_register_device(&analog_dev);
+	gameport_register_driver(&analog_drv);
 	return 0;
 }
 
 static void __exit analog_exit(void)
 {
-	gameport_unregister_device(&analog_dev);
+	gameport_unregister_driver(&analog_drv);
 }
 
 module_init(analog_init);
drivers/input/joystick/cobra.c +5 -5
diff -Nru a/drivers/input/joystick/cobra.c b/drivers/input/joystick/cobra.c
@@ -158,7 +158,7 @@
 		del_timer(&cobra->timer);
 }
 
-static void cobra_connect(struct gameport *gameport, struct gameport_dev *dev)
+static void cobra_connect(struct gameport *gameport, struct gameport_driver *drv)
 {
 	struct cobra *cobra;
 	unsigned int data[2];
@@ -175,7 +175,7 @@
 	cobra->timer.data = (long) cobra;
 	cobra->timer.function = cobra_timer;
 
-	if (gameport_open(gameport, dev, GAMEPORT_MODE_RAW))
+	if (gameport_open(gameport, drv, GAMEPORT_MODE_RAW))
 		goto fail1;
 
 	cobra->exists = cobra_read_packet(gameport, data);
@@ -236,20 +236,20 @@
 	kfree(cobra);
 }
 
-static struct gameport_dev cobra_dev = {
+static struct gameport_driver cobra_drv = {
 	.connect =	cobra_connect,
 	.disconnect =	cobra_disconnect,
 };
 
 static int __init cobra_init(void)
 {
-	gameport_register_device(&cobra_dev);
+	gameport_register_driver(&cobra_drv);
 	return 0;
 }
 
 static void __exit cobra_exit(void)
 {
-	gameport_unregister_device(&cobra_dev);
+	gameport_unregister_driver(&cobra_drv);
 }
 
 module_init(cobra_init);
drivers/input/joystick/gf2k.c +5 -5
diff -Nru a/drivers/input/joystick/gf2k.c b/drivers/input/joystick/gf2k.c
@@ -238,7 +238,7 @@
  * gf2k_connect() probes for Genius id joysticks.
  */
 
-static void gf2k_connect(struct gameport *gameport, struct gameport_dev *dev)
+static void gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
 {
 	struct gf2k *gf2k;
 	unsigned char data[GF2K_LENGTH];
@@ -255,7 +255,7 @@
 	gf2k->timer.data = (long) gf2k;
 	gf2k->timer.function = gf2k_timer;
 
-	if (gameport_open(gameport, dev, GAMEPORT_MODE_RAW))
+	if (gameport_open(gameport, drv, GAMEPORT_MODE_RAW))
 		goto fail1;
 
 	gf2k_trigger_seq(gameport, gf2k_seq_reset);
@@ -346,20 +346,20 @@
 	kfree(gf2k);
 }
 
-static struct gameport_dev gf2k_dev = {
+static struct gameport_driver gf2k_drv = {
 	.connect =	gf2k_connect,
 	.disconnect =	gf2k_disconnect,
 };
 
 static int __init gf2k_init(void)
 {
-	gameport_register_device(&gf2k_dev);
+	gameport_register_driver(&gf2k_drv);
 	return 0;
 }
 
 static void __exit gf2k_exit(void)
 {
-	gameport_unregister_device(&gf2k_dev);
+	gameport_unregister_driver(&gf2k_drv);
 }
 
 module_init(gf2k_init);
drivers/input/joystick/grip.c +5 -5
diff -Nru a/drivers/input/joystick/grip.c b/drivers/input/joystick/grip.c
@@ -298,7 +298,7 @@
 		del_timer(&grip->timer);
 }
 
-static void grip_connect(struct gameport *gameport, struct gameport_dev *dev)
+static void grip_connect(struct gameport *gameport, struct gameport_driver *drv)
 {
 	struct grip *grip;
 	unsigned int data[GRIP_LENGTH_XT];
@@ -315,7 +315,7 @@
 	grip->timer.data = (long) grip;
 	grip->timer.function = grip_timer;
 
-	 if (gameport_open(gameport, dev, GAMEPORT_MODE_RAW))
+	 if (gameport_open(gameport, drv, GAMEPORT_MODE_RAW))
 		goto fail1;
 
 	for (i = 0; i < 2; i++) {
@@ -409,20 +409,20 @@
 	kfree(grip);
 }
 
-static struct gameport_dev grip_dev = {
+static struct gameport_driver grip_drv = {
 	.connect =	grip_connect,
 	.disconnect =	grip_disconnect,
 };
 
 static int __init grip_init(void)
 {
-	gameport_register_device(&grip_dev);
+	gameport_register_driver(&grip_drv);
 	return 0;
 }
 
 static void __exit grip_exit(void)
 {
-	gameport_unregister_device(&grip_dev);
+	gameport_unregister_driver(&grip_drv);
 }
 
 module_init(grip_init);
drivers/input/joystick/grip_mp.c +5 -5
diff -Nru a/drivers/input/joystick/grip_mp.c b/drivers/input/joystick/grip_mp.c
@@ -616,7 +616,7 @@
 	mod_timer(&grip->timer, jiffies + GRIP_REFRESH_TIME);
 }
 
-static void grip_connect(struct gameport *gameport, struct gameport_dev *dev)
+static void grip_connect(struct gameport *gameport, struct gameport_driver *drv)
 {
 	struct grip_mp *grip;
 
@@ -629,7 +629,7 @@
 	grip->timer.data = (long) grip;
 	grip->timer.function = grip_timer;
 
-	if (gameport_open(gameport, dev, GAMEPORT_MODE_RAW))
+	if (gameport_open(gameport, drv, GAMEPORT_MODE_RAW))
 		goto fail1;
 	if (!multiport_init(grip))
 		goto fail2;
@@ -654,20 +654,20 @@
 	kfree(grip);
 }
 
-static struct gameport_dev grip_dev = {
+static struct gameport_driver grip_drv = {
 	.connect	= grip_connect,
 	.disconnect	= grip_disconnect,
 };
 
 static int grip_init(void)
 {
-	gameport_register_device(&grip_dev);
+	gameport_register_driver(&grip_drv);
 	return 0;
 }
 
 static void grip_exit(void)
 {
-	gameport_unregister_device(&grip_dev);
+	gameport_unregister_driver(&grip_drv);
 }
 
 module_init(grip_init);
drivers/input/joystick/guillemot.c +5 -5
diff -Nru a/drivers/input/joystick/guillemot.c b/drivers/input/joystick/guillemot.c
@@ -179,7 +179,7 @@
  * guillemot_connect() probes for Guillemot joysticks.
  */
 
-static void guillemot_connect(struct gameport *gameport, struct gameport_dev *dev)
+static void guillemot_connect(struct gameport *gameport, struct gameport_driver *drv)
 {
 	struct guillemot *guillemot;
 	u8 data[GUILLEMOT_MAX_LENGTH];
@@ -196,7 +196,7 @@
 	guillemot->timer.data = (long) guillemot;
 	guillemot->timer.function = guillemot_timer;
 
-	if (gameport_open(gameport, dev, GAMEPORT_MODE_RAW))
+	if (gameport_open(gameport, drv, GAMEPORT_MODE_RAW))
 		goto fail1;
 
 	i = guillemot_read_packet(gameport, data);
@@ -266,20 +266,20 @@
 	kfree(guillemot);
 }
 
-static struct gameport_dev guillemot_dev = {
+static struct gameport_driver guillemot_drv = {
 	.connect =	guillemot_connect,
 	.disconnect =	guillemot_disconnect,
 };
 
 static int __init guillemot_init(void)
 {
-	gameport_register_device(&guillemot_dev);
+	gameport_register_driver(&guillemot_drv);
 	return 0;
 }
 
 static void __exit guillemot_exit(void)
 {
-	gameport_unregister_device(&guillemot_dev);
+	gameport_unregister_driver(&guillemot_drv);
 }
 
 module_init(guillemot_init);
drivers/input/joystick/interact.c +5 -5
diff -Nru a/drivers/input/joystick/interact.c b/drivers/input/joystick/interact.c
@@ -209,7 +209,7 @@
  * interact_connect() probes for InterAct joysticks.
  */
 
-static void interact_connect(struct gameport *gameport, struct gameport_dev *dev)
+static void interact_connect(struct gameport *gameport, struct gameport_driver *drv)
 {
 	struct interact *interact;
 	__u32 data[3];
@@ -226,7 +226,7 @@
 	interact->timer.data = (long) interact;
 	interact->timer.function = interact_timer;
 
-	if (gameport_open(gameport, dev, GAMEPORT_MODE_RAW))
+	if (gameport_open(gameport, drv, GAMEPORT_MODE_RAW))
 		goto fail1;
 
 	i = interact_read_packet(gameport, INTERACT_MAX_LENGTH * 2, data);
@@ -294,20 +294,20 @@
 	kfree(interact);
 }
 
-static struct gameport_dev interact_dev = {
+static struct gameport_driver interact_drv = {
 	.connect =	interact_connect,
 	.disconnect =	interact_disconnect,
 };
 
 static int __init interact_init(void)
 {
-	gameport_register_device(&interact_dev);
+	gameport_register_driver(&interact_drv);
 	return 0;
 }
 
 static void __exit interact_exit(void)
 {
-	gameport_unregister_device(&interact_dev);
+	gameport_unregister_driver(&interact_drv);
 }
 
 module_init(interact_init);
drivers/input/joystick/joydump.c +6 -6
diff -Nru a/drivers/input/joystick/joydump.c b/drivers/input/joystick/joydump.c
@@ -46,7 +46,7 @@
 	unsigned char data;
 };
 
-static void __devinit joydump_connect(struct gameport *gameport, struct gameport_dev *dev)
+static void __devinit joydump_connect(struct gameport *gameport, struct gameport_driver *drv)
 {
 	struct joydump *buf;	/* all entries */
 	struct joydump *dump, *prev;	/* one entry each */
@@ -59,11 +59,11 @@
 	printk(KERN_INFO "joydump: | Dumping gameport%s.\n", gameport->phys);
 	printk(KERN_INFO "joydump: | Speed: %4d kHz.                            |\n", gameport->speed);
 
-	if (gameport_open(gameport, dev, GAMEPORT_MODE_RAW)) {
+	if (gameport_open(gameport, drv, GAMEPORT_MODE_RAW)) {
 
 		printk(KERN_INFO "joydump: | Raw mode not available - trying cooked.    |\n");
 
-		if (gameport_open(gameport, dev, GAMEPORT_MODE_COOKED)) {
+		if (gameport_open(gameport, drv, GAMEPORT_MODE_COOKED)) {
 
 			printk(KERN_INFO "joydump: | Cooked not available either. Failing.      |\n");
 			printk(KERN_INFO "joydump: `-------------------- END -------------------'\n");
@@ -147,20 +147,20 @@
 	gameport_close(gameport);
 }
 
-static struct gameport_dev joydump_dev = {
+static struct gameport_driver joydump_drv = {
 	.connect =	joydump_connect,
 	.disconnect =	joydump_disconnect,
 };
 
 static int __init joydump_init(void)
 {
-	gameport_register_device(&joydump_dev);
+	gameport_register_driver(&joydump_drv);
 	return 0;
 }
 
 static void __exit joydump_exit(void)
 {
-	gameport_unregister_device(&joydump_dev);
+	gameport_unregister_driver(&joydump_drv);
 }
 
 module_init(joydump_init);
drivers/input/joystick/sidewinder.c +5 -5
diff -Nru a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
@@ -569,7 +569,7 @@
  * sw_connect() probes for SideWinder type joysticks.
  */
 
-static void sw_connect(struct gameport *gameport, struct gameport_dev *dev)
+static void sw_connect(struct gameport *gameport, struct gameport_driver *drv)
 {
 	struct sw *sw;
 	int i, j, k, l;
@@ -595,7 +595,7 @@
 	sw->timer.data = (long) sw;
 	sw->timer.function = sw_timer;
 
-	if (gameport_open(gameport, dev, GAMEPORT_MODE_RAW))
+	if (gameport_open(gameport, drv, GAMEPORT_MODE_RAW))
 		goto fail1;
 
 	dbg("Init 0: Opened %s, io %#x, speed %d",
@@ -760,20 +760,20 @@
 	kfree(sw);
 }
 
-static struct gameport_dev sw_dev = {
+static struct gameport_driver sw_drv = {
 	.connect =	sw_connect,
 	.disconnect =	sw_disconnect,
 };
 
 static int __init sw_init(void)
 {
-	gameport_register_device(&sw_dev);
+	gameport_register_driver(&sw_drv);
 	return 0;
 }
 
 static void __exit sw_exit(void)
 {
-	gameport_unregister_device(&sw_dev);
+	gameport_unregister_driver(&sw_drv);
 }
 
 module_init(sw_init);
drivers/input/joystick/tmdc.c +5 -5
diff -Nru a/drivers/input/joystick/tmdc.c b/drivers/input/joystick/tmdc.c
@@ -242,7 +242,7 @@
  * tmdc_probe() probes for ThrustMaster type joysticks.
  */
 
-static void tmdc_connect(struct gameport *gameport, struct gameport_dev *dev)
+static void tmdc_connect(struct gameport *gameport, struct gameport_driver *drv)
 {
 	struct models {
 		unsigned char id;
@@ -275,7 +275,7 @@
 	tmdc->timer.data = (long) tmdc;
 	tmdc->timer.function = tmdc_timer;
 
-	if (gameport_open(gameport, dev, GAMEPORT_MODE_RAW))
+	if (gameport_open(gameport, drv, GAMEPORT_MODE_RAW))
 		goto fail1;
 
 	if (!(tmdc->exists = tmdc_read_packet(gameport, data)))
@@ -362,20 +362,20 @@
 	kfree(tmdc);
 }
 
-static struct gameport_dev tmdc_dev = {
+static struct gameport_driver tmdc_drv = {
 	.connect =	tmdc_connect,
 	.disconnect =	tmdc_disconnect,
 };
 
 static int __init tmdc_init(void)
 {
-	gameport_register_device(&tmdc_dev);
+	gameport_register_driver(&tmdc_drv);
 	return 0;
 }
 
 static void __exit tmdc_exit(void)
 {
-	gameport_unregister_device(&tmdc_dev);
+	gameport_unregister_driver(&tmdc_drv);
 }
 
 module_init(tmdc_init);
include/linux/gameport.h +6 -6
diff -Nru a/include/linux/gameport.h b/include/linux/gameport.h
@@ -35,23 +35,23 @@
 	int (*open)(struct gameport *, int);
 	void (*close)(struct gameport *);
 
-	struct gameport_dev *dev;
+	struct gameport_driver *drv;
 
 	struct list_head node;
 };
 
-struct gameport_dev {
+struct gameport_driver {
 
 	void *private;
 	char *name;
 
-	void (*connect)(struct gameport *, struct gameport_dev *dev);
+	void (*connect)(struct gameport *, struct gameport_driver *drv);
 	void (*disconnect)(struct gameport *);
 
 	struct list_head node;
 };
 
-int gameport_open(struct gameport *gameport, struct gameport_dev *dev, int mode);
+int gameport_open(struct gameport *gameport, struct gameport_driver *drv, int mode);
 void gameport_close(struct gameport *gameport);
 void gameport_rescan(struct gameport *gameport);
 
@@ -63,8 +63,8 @@
 static inline void gameport_unregister_port(struct gameport *gameport) { return; }
 #endif
 
-void gameport_register_device(struct gameport_dev *dev);
-void gameport_unregister_device(struct gameport_dev *dev);
+void gameport_register_driver(struct gameport_driver *drv);
+void gameport_unregister_driver(struct gameport_driver *drv);
 
 #define GAMEPORT_MODE_DISABLED		0
 #define GAMEPORT_MODE_RAW		1

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click

#3 lore raw

PATCH 3/10 Gameport: connect() is mandatory

===================================================================

[email protected], 2005-02-11 01:18:29-05:00, [email protected]
Input: make connect and disconnect methods mandatory for gameport
drivers since that's where gameport_{open|close} are called from to actually bind driver to a port.

 gameport.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

===================================================================

drivers/input/gameport/gameport.c +4 -5
diff -Nru a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
@@ -107,8 +107,7 @@
         list_for_each_entry(drv, &gameport_driver_list, node) {
 		if (gameport->drv)
 			break;
-		if (drv->connect)
-                	drv->connect(gameport, drv);
+               	drv->connect(gameport, drv);
         }
 }
 
@@ -128,7 +127,7 @@
 void gameport_unregister_port(struct gameport *gameport)
 {
 	list_del_init(&gameport->node);
-	if (gameport->drv && gameport->drv->disconnect)
+	if (gameport->drv)
 		gameport->drv->disconnect(gameport);
 }
 
@@ -138,7 +137,7 @@
 
 	list_add_tail(&drv->node, &gameport_driver_list);
 	list_for_each_entry(gameport, &gameport_list, node)
-		if (!gameport->drv && drv->connect)
+		if (!gameport->drv)
 			drv->connect(gameport, drv);
 }
 
@@ -148,7 +147,7 @@
 
 	list_del_init(&drv->node);
 	list_for_each_entry(gameport, &gameport_list, node) {
-		if (gameport->drv == drv && drv->disconnect)
+		if (gameport->drv == drv)
 			drv->disconnect(gameport);
 		gameport_find_driver(gameport);
 	}

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click

#4 lore raw

PATCH 4/10 Gameport: prepare to dynamic allocation

===================================================================

[email protected], 2005-02-11 01:18:48-05:00, [email protected]
Input: prepare for dynamic gameport allocation:
- provide functions to allocate and free gameports;
- provide functions to properly set name and phys;
- dynamically allocated gameports are automatically announced in kernel logs and freed when unregistered.

 drivers/input/gameport/gameport.c |   24 ++++++++++++++++++++++++
 include/linux/gameport.h          |   38 +++++++++++++++++++++++++++++++-------
 2 files changed, 55 insertions(+), 7 deletions(-)

===================================================================

drivers/input/gameport/gameport.c +24 -0
diff -Nru a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
@@ -31,6 +31,8 @@
 EXPORT_SYMBOL(gameport_close);
 EXPORT_SYMBOL(gameport_rescan);
 EXPORT_SYMBOL(gameport_cooked_read);
+EXPORT_SYMBOL(gameport_set_name);
+EXPORT_SYMBOL(gameport_set_phys);
 
 static LIST_HEAD(gameport_list);
 static LIST_HEAD(gameport_driver_list);
@@ -117,10 +119,30 @@
 	gameport_find_driver(gameport);
 }
 
+void gameport_set_phys(struct gameport *gameport, const char *fmt, ...)
+{
+	va_list args;
+
+	va_start(args, fmt);
+	gameport->phys = gameport->phys_buf;
+	vsnprintf(gameport->phys_buf, sizeof(gameport->phys_buf), fmt, args);
+	va_end(args);
+}
+
 void gameport_register_port(struct gameport *gameport)
 {
 	list_add_tail(&gameport->node, &gameport_list);
 	gameport->speed = gameport_measure_speed(gameport);
+
+	if (gameport->dyn_alloc) {
+		if (gameport->io)
+			printk(KERN_INFO "gameport: %s is %s, io %#x, speed %d kHz\n",
+				gameport->name, gameport->phys, gameport->io, gameport->speed);
+		else
+			printk(KERN_INFO "gameport: %s is %s, speed %d kHz\n",
+				gameport->name, gameport->phys, gameport->speed);
+	}
+
 	gameport_find_driver(gameport);
 }
 
@@ -129,6 +151,8 @@
 	list_del_init(&gameport->node);
 	if (gameport->drv)
 		gameport->drv->disconnect(gameport);
+	if (gameport->dyn_alloc)
+		kfree(gameport);
 }
 
 void gameport_register_driver(struct gameport_driver *drv)
include/linux/gameport.h +31 -7
diff -Nru a/include/linux/gameport.h b/include/linux/gameport.h
@@ -12,15 +12,16 @@
 #include <asm/io.h>
 #include <linux/input.h>
 #include <linux/list.h>
-
-struct gameport;
+#include <linux/device.h>
 
 struct gameport {
 
 	void *private;		/* Private pointer for joystick drivers */
 	void *port_data;	/* Private pointer for gameport drivers */
 	char *name;
+	char name_buf[32];
 	char *phys;
+	char phys_buf[32];
 
 	struct input_id id;
 
@@ -36,8 +37,12 @@
 	void (*close)(struct gameport *);
 
 	struct gameport_driver *drv;
+	struct device dev;
 
 	struct list_head node;
+
+	/* temporary, till sysfs transition is complete */
+	int dyn_alloc;
 };
 
 struct gameport_driver {
@@ -55,13 +60,32 @@
 void gameport_close(struct gameport *gameport);
 void gameport_rescan(struct gameport *gameport);
 
-#if defined(CONFIG_GAMEPORT) || defined(CONFIG_GAMEPORT_MODULE)
+static inline struct gameport *gameport_allocate_port(void)
+{
+	struct gameport *gameport = kcalloc(1, sizeof(struct gameport), GFP_KERNEL);
+
+	if (gameport)
+		gameport->dyn_alloc = 1;
+
+	return gameport;
+}
+
+static inline void gameport_free_port(struct gameport *gameport)
+{
+	kfree(gameport);
+}
+
+static inline void gameport_set_name(struct gameport *gameport, const char *name)
+{
+	gameport->name = gameport->name_buf;
+	strlcpy(gameport->name, name, sizeof(gameport->name_buf));
+}
+
+void gameport_set_phys(struct gameport *gameport, const char *fmt, ...)
+	__attribute__ ((format (printf, 2, 3)));
+
 void gameport_register_port(struct gameport *gameport);
 void gameport_unregister_port(struct gameport *gameport);
-#else
-static inline void gameport_register_port(struct gameport *gameport) { return; }
-static inline void gameport_unregister_port(struct gameport *gameport) { return; }
-#endif
 
 void gameport_register_driver(struct gameport_driver *drv);
 void gameport_unregister_driver(struct gameport_driver *drv);

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click

#5 lore raw

PATCH 5/10 Gameport: convert input/gameport to dynamic allocation

===================================================================

[email protected], 2005-02-11 01:19:36-05:00, [email protected]
Input: convert input/gameport to dynamic gameport allocation.

 drivers/input/gameport/cs461x.c     |   29 +----
 drivers/input/gameport/emu10k1-gp.c |   40 ++++----
 drivers/input/gameport/fm801-gp.c   |   57 +++++------
 drivers/input/gameport/lightning.c  |  176 ++++++++++++++++++++++--------------
 drivers/input/gameport/ns558.c      |  120 +++++++++++-------------
 drivers/input/gameport/vortex.c     |   68 ++++++-------
 drivers/input/joystick/a3d.c        |   59 +++++-------
 include/linux/gameport.h            |    3 
 8 files changed, 286 insertions(+), 266 deletions(-)

===================================================================

drivers/input/gameport/cs461x.c +9 -20
diff -Nru a/drivers/input/gameport/cs461x.c b/drivers/input/gameport/cs461x.c
@@ -120,9 +120,6 @@
 static unsigned long ba0_addr;
 static unsigned int __iomem *ba0;
 
-static char phys[32];
-static char name[] = "CS416x Gameport";
-
 #ifdef CS461X_FULL_MAP
 static unsigned long ba1_addr;
 static union ba1_t {
@@ -160,10 +157,10 @@
 static int cs461x_free(struct pci_dev *pdev)
 {
 	struct gameport *port = pci_get_drvdata(pdev);
-	if(port){
+
+	if (port)
 	    gameport_unregister_port(port);
-	    kfree(port);
-	}
+
 	if (ba0) iounmap(ba0);
 #ifdef CS461X_FULL_MAP
 	if (ba1.name.data0) iounmap(ba1.name.data0);
@@ -267,18 +264,17 @@
                 return -ENOMEM;
         }
 #else
-	if (ba0 == NULL){
+	if (ba0 == NULL) {
 		cs461x_free(pdev);
 		return -ENOMEM;
 	}
 #endif
 
-	if (!(port = kmalloc(sizeof(struct gameport), GFP_KERNEL))) {
-		printk(KERN_ERR "Memory allocation failed.\n");
+	if (!(port = gameport_allocate_port())) {
+		printk(KERN_ERR "cs461x: Memory allocation failed\n");
 		cs461x_free(pdev);
 		return -ENOMEM;
 	}
-	memset(port, 0, sizeof(struct gameport));
 
 	pci_set_drvdata(pdev, port);
 
@@ -287,21 +283,14 @@
 	port->read = cs461x_gameport_read;
 	port->cooked_read = cs461x_gameport_cooked_read;
 
-	sprintf(phys, "pci%s/gameport0", pci_name(pdev));
-
-	port->name = name;
-	port->phys = phys;
-	port->id.bustype = BUS_PCI;
-	port->id.vendor = pdev->vendor;
-	port->id.product = pdev->device;
+	gameport_set_name(port, "CS416x");
+	gameport_set_phys(port, "pci%s/gameport0", pci_name(pdev));
+	port->dev.parent = &pdev->dev;
 
 	cs461x_pokeBA0(BA0_JSIO, 0xFF); // ?
 	cs461x_pokeBA0(BA0_JSCTL, JSCTL_SP_MEDIUM_SLOW);
 
 	gameport_register_port(port);
-
-	printk(KERN_INFO "gameport: %s on pci%s speed %d kHz\n",
-		name, pci_name(pdev), port->speed);
 
 	return 0;
 }
drivers/input/gameport/emu10k1-gp.c +20 -20
diff -Nru a/drivers/input/gameport/emu10k1-gp.c b/drivers/input/gameport/emu10k1-gp.c
@@ -44,13 +44,13 @@
 
 struct emu {
 	struct pci_dev *dev;
-	struct gameport gameport;
+	struct gameport *gameport;
+	int io;
 	int size;
-	char phys[32];
 };
 
 static struct pci_device_id emu_tbl[] = {
- 
+
 	{ 0x1102, 0x7002, PCI_ANY_ID, PCI_ANY_ID }, /* SB Live gameport */
 	{ 0x1102, 0x7003, PCI_ANY_ID, PCI_ANY_ID }, /* Audigy gameport */
 	{ 0x1102, 0x7004, PCI_ANY_ID, PCI_ANY_ID }, /* Dell SB Live */
@@ -64,6 +64,7 @@
 {
 	int ioport, iolen;
 	struct emu *emu;
+	struct gameport *port;
 
 	if (pci_enable_device(pdev))
 		return -EBUSY;
@@ -74,31 +75,29 @@
 	if (!request_region(ioport, iolen, "emu10k1-gp"))
 		return -EBUSY;
 
-	if (!(emu = kmalloc(sizeof(struct emu), GFP_KERNEL))) {
-		printk(KERN_ERR "emu10k1-gp: Memory allocation failed.\n");
+	emu = kcalloc(1, sizeof(struct emu), GFP_KERNEL);
+	port = gameport_allocate_port();
+	if (!emu || !port) {
+		printk(KERN_ERR "emu10k1-gp: Memory allocation failed\n");
 		release_region(ioport, iolen);
+		kfree(emu);
+		gameport_free_port(port);
 		return -ENOMEM;
 	}
-	memset(emu, 0, sizeof(struct emu));
-
-	sprintf(emu->phys, "pci%s/gameport0", pci_name(pdev));
 
+	emu->io = ioport;
 	emu->size = iolen;
 	emu->dev = pdev;
+	emu->gameport = port;
 
-	emu->gameport.io = ioport;
-	emu->gameport.name = pci_name(pdev);
-	emu->gameport.phys = emu->phys;
-	emu->gameport.id.bustype = BUS_PCI;
-	emu->gameport.id.vendor = pdev->vendor;
-	emu->gameport.id.product = pdev->device;
+	gameport_set_name(port, "EMU10K1");
+	gameport_set_phys(port, "pci%s/gameport0", pci_name(pdev));
+	port->dev.parent = &pdev->dev;
+	port->io = ioport;
 
 	pci_set_drvdata(pdev, emu);
 
-	gameport_register_port(&emu->gameport);
-
-	printk(KERN_INFO "gameport: pci%s speed %d kHz\n",
-		pci_name(pdev), emu->gameport.speed);
+	gameport_register_port(port);
 
 	return 0;
 }
@@ -106,8 +105,9 @@
 static void __devexit emu_remove(struct pci_dev *pdev)
 {
 	struct emu *emu = pci_get_drvdata(pdev);
-	gameport_unregister_port(&emu->gameport);
-	release_region(emu->gameport.io, emu->size);
+
+	gameport_unregister_port(emu->gameport);
+	release_region(emu->io, emu->size);
 	kfree(emu);
 }
 
drivers/input/gameport/fm801-gp.c +29 -28

87 lines not on this page · raw message

drivers/input/gameport/lightning.c +108 -68

271 lines not on this page · raw message

drivers/input/gameport/ns558.c +58 -62

210 lines not on this page · raw message

drivers/input/gameport/vortex.c +34 -34

104 lines not on this page · raw message

drivers/input/joystick/a3d.c +28 -31

111 lines not on this page · raw message

include/linux/gameport.h +0 -3
diff -Nru a/include/linux/gameport.h b/include/linux/gameport.h
@@ -10,7 +10,6 @@
  */
 
 #include <asm/io.h>
-#include <linux/input.h>
 #include <linux/list.h>
 #include <linux/device.h>
 
@@ -22,8 +21,6 @@
 	char name_buf[32];
 	char *phys;
 	char phys_buf[32];
-
-	struct input_id id;
 
 	int io;
 	int speed;

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click

#6 lore raw

PATCH 6/10 Gameport: convert sound/oss to dynamic allocation

===================================================================

[email protected], 2005-02-11 01:20:08-05:00, [email protected]
Input: convert sound/oss to dynamic gameport allocation.

 cmpci.c      |  100 ++++++++++++++++++++++++++++++++++++++---------------------
 es1370.c     |   34 ++++++++++++--------
 es1371.c     |   52 ++++++++++++++++++------------
 esssolo1.c   |   47 ++++++++++++++++++++-------
 mad16.c      |   47 ++++++++++++++++++---------
 sonicvibes.c |   49 +++++++++++++++++++++-------
 trident.c    |   39 +++++++++++++++++------
 7 files changed, 249 insertions(+), 119 deletions(-)

===================================================================

sound/oss/cmpci.c +65 -35
diff -Nru a/sound/oss/cmpci.c b/sound/oss/cmpci.c
@@ -426,7 +426,7 @@
 	struct address_info mpu_data;
 #endif
 #ifdef CONFIG_SOUND_CMPCI_JOYSTICK
-	struct gameport gameport;
+	struct gameport *gameport;
 #endif
 
 	int	chip_version;
@@ -468,17 +468,17 @@
 
 static LIST_HEAD(devs);
 
-static	int	mpuio = 0;
-static	int	fmio = 0;
-static	int	joystick = 0;
-static	int	spdif_inverse = 0;
-static	int	spdif_loop = 0;
-static	int	spdif_out = 0;
-static	int	use_line_as_rear = 0;
-static	int	use_line_as_bass = 0;
-static	int	use_mic_as_bass = 0;
-static	int	mic_boost = 0;
-static	int	hw_copy = 0;
+static	int	mpuio;
+static	int	fmio;
+static	int	joystick;
+static	int	spdif_inverse;
+static	int	spdif_loop;
+static	int	spdif_out;
+static	int	use_line_as_rear;
+static	int	use_line_as_bass;
+static	int	use_mic_as_bass;
+static	int	mic_boost;
+static	int	hw_copy;
 module_param(mpuio, int, 0);
 module_param(fmio, int, 0);
 module_param(joystick, bool, 0);
@@ -2984,6 +2984,51 @@
 	return ChipVersion;
 }
 
+#ifdef CONFIG_SOUND_CMPCI_JOYSTICK
+static int __devinit cm_create_gameport(struct cm_state *s, int io_port)
+{
+	struct gameport *gp;
+
+	if (!request_region(io_port, CM_EXTENT_GAME, "cmpci GAME")) {
+		printk(KERN_ERR "cmpci: gameport io ports 0x%#x in use\n", io_port);
+		return -EBUSY;
+	}
+
+	if (!(s->gameport = gp = gameport_allocate_port())) {
+		printk(KERN_ERR "cmpci: can not allocate memory for gameport\n");
+		release_region(io_port, CM_EXTENT_GAME);
+		return -ENOMEM;
+	}
+
+	gameport_set_name(gp, "C-Media GP");
+	gameport_set_phys(gp, "pci%s/gameport0", pci_name(s->dev));
+	gp->dev.parent = &s->dev->dev;
+	gp->io = io_port;
+
+	/* enable joystick */
+	maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0, 0x02);
+
+	gameport_register_port(gp);
+
+	return 0;
+}
+
+static void __devexit cm_free_gameport(struct cm_state *s)
+{
+	if (s->gameport) {
+		int gpio = s->gameport->io;
+
+		gameport_unregister_port(s->gameport);
+		s->gameport = NULL;
+		maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0x02, 0);
+		release_region(gpio, CM_EXTENT_GAME);
+	}
+}
+#else
+static inline int cm_create_gameport(struct cm_state *s, int io_port) { return -ENOSYS; }
+static inline void cm_free_gameport(struct cm_state *s) { }
+#endif
+
 #define	echo_option(x)\
 if (x) strcat(options, "" #x " ")
 
@@ -3229,22 +3274,11 @@
 	}
 skip_mpu:
 #endif
-#ifdef CONFIG_SOUND_CMPCI_JOYSTICK
-	/* enable joystick */
-	if (joystick) {
-		s->gameport.io = 0x200;
-		if (!request_region(s->gameport.io, CM_EXTENT_GAME, "cmpci GAME")) {
-			printk(KERN_ERR "cmpci: gameport io ports in use\n");
-			s->gameport.io = 0;
-	       	} else {
-			maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0, 0x02);
-			gameport_register_port(&s->gameport);
-		}
-	} else {
-		maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0x02, 0);
-		s->gameport.io = 0;
-	}
-#endif
+	/* disable joystick port */
+	maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0x02, 0);
+	if (joystick)
+		cm_create_gameport(s, 0x200);
+
 	/* store it in the driver field */
 	pci_set_drvdata(pcidev, s);
 	/* put it into driver list */
@@ -3278,13 +3312,9 @@
 
 	if (!s)
 		return;
-#ifdef CONFIG_SOUND_CMPCI_JOYSTICK
-	if (s->gameport.io) {
-		gameport_unregister_port(&s->gameport);
-		release_region(s->gameport.io, CM_EXTENT_GAME);
-		maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0x02, 0);
-	}
-#endif
+
+	cm_free_gameport(s);
+
 #ifdef CONFIG_SOUND_CMPCI_FM
 	if (s->iosynth) {
 		/* disable FM */
sound/oss/es1370.c +22 -12
diff -Nru a/sound/oss/es1370.c b/sound/oss/es1370.c
@@ -384,7 +384,7 @@
 		unsigned char obuf[MIDIOUTBUF];
 	} midi;
 
-	struct gameport gameport;
+	struct gameport *gameport;
 	struct semaphore sem;
 };
 
@@ -2556,6 +2556,7 @@
 static int __devinit es1370_probe(struct pci_dev *pcidev, const struct pci_device_id *pciid)
 {
 	struct es1370_state *s;
+	struct gameport *gp = NULL;
 	mm_segment_t fs;
 	int i, val, ret;
 
@@ -2604,12 +2605,17 @@
 	/* note: setting CTRL_SERR_DIS is reported to break
 	 * mic bias setting (by [email protected]) */
 	s->ctrl = CTRL_CDC_EN | (DAC2_SRTODIV(8000) << CTRL_SH_PCLKDIV) | (1 << CTRL_SH_WTSRSEL);
-	s->gameport.io = 0;
-	if (!request_region(0x200, JOY_EXTENT, "es1370"))
+	if (!request_region(0x200, JOY_EXTENT, "es1370")) {
 		printk(KERN_ERR "es1370: joystick io port 0x200 in use\n");
-	else {
+	} else if (!(s->gameport = gp = gameport_allocate_port())) {
+		printk(KERN_ERR "es1370: can not allocate memory for gameport\n");
+		release_region(0x200, JOY_EXTENT);
+	} else {
+		gameport_set_name(gp, "ESS1370");
+		gameport_set_phys(gp, "pci%s/gameport0", pci_name(s->dev));
+		gp->dev.parent = &s->dev->dev;
+		gp->io = 0x200;
 		s->ctrl |= CTRL_JYSTK_EN;
-		s->gameport.io = 0x200;
 	}
 	if (lineout[devindex])
 		s->ctrl |= CTRL_XCTL0;
@@ -2665,9 +2671,10 @@
 		mixer_ioctl(s, initvol[i].mixch, (unsigned long)&val);
 	}
 	set_fs(fs);
+
 	/* register gameport */
-	if (s->gameport.io)
-		gameport_register_port(&s->gameport);
+	if (gp)
+		gameport_register_port(gp);
 
 	/* store it in the driver field */
 	pci_set_drvdata(pcidev, s);
@@ -2689,8 +2696,10 @@
  err_dev1:
 	printk(KERN_ERR "es1370: cannot register misc device\n");
 	free_irq(s->irq, s);
-	if (s->gameport.io)
-		release_region(s->gameport.io, JOY_EXTENT);
+	if (s->gameport) {
+		release_region(s->gameport->io, JOY_EXTENT);
+		gameport_free_port(s->gameport);
+	}
  err_irq:
 	release_region(s->io, ES1370_EXTENT);
  err_region:
@@ -2709,9 +2718,10 @@
 	outl(0, s->io+ES1370_REG_SERIAL_CONTROL); /* clear serial interrupts */
 	synchronize_irq(s->irq);
 	free_irq(s->irq, s);
-	if (s->gameport.io) {
-		gameport_unregister_port(&s->gameport);
-		release_region(s->gameport.io, JOY_EXTENT);
+	if (s->gameport) {
+		int gpio = s->gameport->io;
+		gameport_unregister_port(s->gameport);
+		release_region(gpio, JOY_EXTENT);
 	}
 	release_region(s->io, ES1370_EXTENT);
 	unregister_sound_dsp(s->dev_audio);
sound/oss/es1371.c +32 -20

101 lines not on this page · raw message

sound/oss/esssolo1.c +34 -13

96 lines not on this page · raw message

sound/oss/mad16.c +31 -16

72 lines not on this page · raw message

sound/oss/sonicvibes.c +36 -13

100 lines not on this page · raw message

sound/oss/trident.c +29 -10
diff -Nru a/sound/oss/trident.c b/sound/oss/trident.c
@@ -441,7 +441,7 @@
 	struct timer_list timer;
 
 	/* Game port support */
-	struct gameport gameport;
+	struct gameport *gameport;
 };
 
 enum dmabuf_mode {
@@ -4305,6 +4305,31 @@
 	return 0;
 }
 
+static int __devinit
+trident_register_gameport(struct trident_card *card)
+{
+	struct gameport *gp;
+
+	card->gameport = gp = gameport_allocate_port();
+	if (!gp) {
+		printk(KERN_ERR "trident: can not allocate memory for gameport\n");
+		return -ENOMEM;
+	}
+
+	gameport_set_name(gp, "Trident 4DWave");
+	gameport_set_phys(gp, "pci%s/gameport0", pci_name(card->pci_dev));
+	gp->read = trident_game_read;
+	gp->trigger = trident_game_trigger;
+	gp->cooked_read = trident_game_cooked_read;
+	gp->open = trident_game_open;
+	gp->fuzz = 64;
+	gp->port_data = card;
+
+	gameport_register_port(gp);
+
+	return 0;
+}
+
 /* install the driver, we do not allocate hardware channel nor DMA buffer */ 
 /* now, they are defered until "ACCESS" time (in prog_dmabuf called by */ 
 /* open/read/write/ioctl/mmap) */
@@ -4368,13 +4393,6 @@
 	card->banks[BANK_B].addresses = &bank_b_addrs;
 	card->banks[BANK_B].bitmap = 0UL;
 
-	card->gameport.port_data = card;
-	card->gameport.fuzz = 64;
-	card->gameport.read = trident_game_read;
-	card->gameport.trigger = trident_game_trigger;
-	card->gameport.cooked_read = trident_game_cooked_read;
-	card->gameport.open = trident_game_open;
-
 	init_MUTEX(&card->open_sem);
 	spin_lock_init(&card->lock);
 	init_timer(&card->timer);
@@ -4508,7 +4526,7 @@
 	trident_enable_loop_interrupts(card);
 
 	/* Register gameport */
-	gameport_register_port(&card->gameport);
+	trident_register_gameport(card);
 
 out:
 	return rc;
@@ -4551,7 +4569,8 @@
 	}
 
 	/* Unregister gameport */
-	gameport_unregister_port(&card->gameport);
+	if (card->gameport)
+		gameport_unregister_port(card->gameport);
 
 	/* Kill interrupts, and SP/DIF */
 	trident_disable_loop_interrupts(card);

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click

#7 lore raw

PATCH 7/10 Gameport: convert sound/alsa to dynamic allocation

===================================================================

[email protected], 2005-02-11 01:20:30-05:00, [email protected]
Input: convert sound/pci to dynamic gameport allocation.

 include/sound/cs46xx.h           |    4 -
 include/sound/trident.h          |    4 -
 include/sound/ymfpci.h           |   14 +--
 sound/pci/als4000.c              |  111 +++++++++++++++++++----------
 sound/pci/au88x0/au88x0.c        |    7 -
 sound/pci/au88x0/au88x0.h        |    2 
 sound/pci/au88x0/au88x0_game.c   |   49 ++++++------
 sound/pci/azt3328.c              |  111 +++++++++++++++++------------
 sound/pci/cmipci.c               |  104 ++++++++++++++++++---------
 sound/pci/cs4281.c               |   91 ++++++++++++-----------
 sound/pci/cs46xx/cs46xx_lib.c    |   81 ++++++++++-----------
 sound/pci/ens1370.c              |  122 +++++++++++++++++++++----------
 sound/pci/es1938.c               |   52 ++++++++++---
 sound/pci/es1968.c               |   76 ++++++++++++++-----
 sound/pci/sonicvibes.c           |   55 +++++++++++---
 sound/pci/trident/trident.c      |    2 
 sound/pci/trident/trident_main.c |   87 ++++++++++------------
 sound/pci/via82xx.c              |   89 +++++++++++++++++------
 sound/pci/ymfpci/ymfpci.c        |  149 ++++++++++++++++++++++++---------------
 sound/pci/ymfpci/ymfpci_main.c   |    9 --
 20 files changed, 761 insertions(+), 458 deletions(-)

===================================================================

include/sound/cs46xx.h +2 -2
diff -Nru a/include/sound/cs46xx.h b/include/sound/cs46xx.h
@@ -1720,7 +1720,7 @@
 	snd_kcontrol_t *eapd_switch; /* for amplifier hack */
 	int accept_valid;	/* accept mmap valid (for OSS) */
 
-	struct snd_cs46xx_gameport *gameport;
+	struct gameport *gameport;
 
 #ifdef CONFIG_SND_CS46XX_DEBUG_GPIO
 	int current_gpio;
@@ -1751,6 +1751,6 @@
 int snd_cs46xx_mixer(cs46xx_t *chip);
 int snd_cs46xx_midi(cs46xx_t *chip, int device, snd_rawmidi_t **rmidi);
 int snd_cs46xx_start_dsp(cs46xx_t *chip);
-void snd_cs46xx_gameport(cs46xx_t *chip);
+int snd_cs46xx_gameport(cs46xx_t *chip);
 
 #endif /* __SOUND_CS46XX_H */
include/sound/trident.h +2 -2
diff -Nru a/include/sound/trident.h b/include/sound/trident.h
@@ -448,7 +448,7 @@
 
 	spinlock_t reg_lock;
 
-	struct snd_trident_gameport *gameport;
+	struct gameport *gameport;
 };
 
 int snd_trident_create(snd_card_t * card,
@@ -457,7 +457,7 @@
 		       int pcm_spdif_device,
 		       int max_wavetable_size,
 		       trident_t ** rtrident);
-void snd_trident_gameport(trident_t *trident);
+int snd_trident_create_gameport(trident_t *trident);
 
 int snd_trident_pcm(trident_t * trident, int device, snd_pcm_t **rpcm);
 int snd_trident_foldback_pcm(trident_t * trident, int device, snd_pcm_t **rpcm);
include/sound/ymfpci.h +7 -7
diff -Nru a/include/sound/ymfpci.h b/include/sound/ymfpci.h
@@ -198,6 +198,10 @@
 #define YMFPCI_LEGACY2_IMOD	(1 << 15)	/* legacy IRQ mode */
 /* SIEN:IMOD 0:0 = legacy irq, 0:1 = INTA, 1:0 = serialized IRQ */
 
+#if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
+#define SUPPORT_JOYSTICK
+#endif
+
 /*
  *
  */
@@ -311,9 +315,8 @@
 	struct resource *mpu_res;
 
 	unsigned short old_legacy_ctrl;
-#if defined(CONFIG_GAMEPORT) || defined(CONFIG_GAMEPORT_MODULE)
-	struct resource *joystick_res;
-	struct gameport gameport;
+#ifdef SUPPORT_JOYSTICK
+	struct gameport *gameport;
 #endif
 
 	struct snd_dma_buffer work_ptr;
@@ -381,6 +384,7 @@
 		      struct pci_dev *pci,
 		      unsigned short old_legacy_ctrl,
 		      ymfpci_t ** rcodec);
+void snd_ymfpci_free_gameport(ymfpci_t *chip);
 
 int snd_ymfpci_pcm(ymfpci_t *chip, int device, snd_pcm_t **rpcm);
 int snd_ymfpci_pcm2(ymfpci_t *chip, int device, snd_pcm_t **rpcm);
@@ -388,9 +392,5 @@
 int snd_ymfpci_pcm_4ch(ymfpci_t *chip, int device, snd_pcm_t **rpcm);
 int snd_ymfpci_mixer(ymfpci_t *chip, int rear_switch);
 int snd_ymfpci_timer(ymfpci_t *chip, int device);
-
-#if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
-#define SUPPORT_JOYSTICK
-#endif
 
 #endif /* __SOUND_YMFPCI_H */
sound/pci/als4000.c +73 -38

147 lines not on this page · raw message

sound/pci/au88x0/au88x0.c +3 -4
diff -Nru a/sound/pci/au88x0/au88x0.c b/sound/pci/au88x0/au88x0.c
@@ -290,10 +290,9 @@
 		snd_card_free(card);
 		return err;
 	}
-	if ((err = vortex_gameport_register(chip)) < 0) {
-		snd_card_free(card);
-		return err;
-	}
+
+	vortex_gameport_register(chip);
+
 #if 0
 	if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_VORTEX_SYNTH,
 			       sizeof(snd_vortex_synth_arg_t), &wave) < 0
sound/pci/au88x0/au88x0.h +1 -1
diff -Nru a/sound/pci/au88x0/au88x0.h b/sound/pci/au88x0/au88x0.h
@@ -272,7 +272,7 @@
 
 /* Driver stuff. */
 static int __devinit vortex_gameport_register(vortex_t * card);
-static int __devexit vortex_gameport_unregister(vortex_t * card);
+static void vortex_gameport_unregister(vortex_t * card);
 #ifndef CHIP_AU8820
 static int __devinit vortex_eq_init(vortex_t * vortex);
 static int __devexit vortex_eq_free(vortex_t * vortex);
sound/pci/au88x0/au88x0_game.c +26 -23

65 lines not on this page · raw message

sound/pci/azt3328.c +68 -43

154 lines not on this page · raw message

sound/pci/cmipci.c +70 -34

129 lines not on this page · raw message

sound/pci/cs4281.c +46 -45

151 lines not on this page · raw message

sound/pci/cs46xx/cs46xx_lib.c +39 -42

121 lines not on this page · raw message

sound/pci/ens1370.c +81 -41

163 lines not on this page · raw message

sound/pci/es1938.c +42 -10

82 lines not on this page · raw message

sound/pci/es1968.c +56 -20

100 lines not on this page · raw message

sound/pci/sonicvibes.c +44 -11

90 lines not on this page · raw message

sound/pci/trident/trident.c +1 -1
diff -Nru a/sound/pci/trident/trident.c b/sound/pci/trident/trident.c
@@ -157,7 +157,7 @@
 	}
 #endif
 
-	snd_trident_gameport(trident);
+	snd_trident_create_gameport(trident);
 
 	if ((err = snd_card_register(card)) < 0) {
 		snd_card_free(card);
sound/pci/trident/trident_main.c +42 -45

131 lines not on this page · raw message

sound/pci/via82xx.c +65 -24

130 lines not on this page · raw message

sound/pci/ymfpci/ymfpci.c +92 -57

189 lines not on this page · raw message

sound/pci/ymfpci/ymfpci_main.c +1 -8
diff -Nru a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
@@ -2079,14 +2079,7 @@
 		release_resource(chip->fm_res);
 		kfree_nocheck(chip->fm_res);
 	}
-#ifdef SUPPORT_JOYSTICK
-	if (chip->joystick_res) {
-		if (chip->gameport.io)
-			gameport_unregister_port(&chip->gameport);
-		release_resource(chip->joystick_res);
-		kfree_nocheck(chip->joystick_res);
-	}
-#endif
+	snd_ymfpci_free_gameport(chip);
 	if (chip->reg_area_virt)
 		iounmap(chip->reg_area_virt);
 	if (chip->work_ptr.area)

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click

#8 lore raw

PATCH 8/10 Gameport: add "gameport" sysfs bus, add drivers

===================================================================

[email protected], 2005-02-11 01:21:02-05:00, [email protected]
Input: integrate gameport drivers info dribver model/sysfs,
create "gameport" bus. drivers' connect() routines now return error code instead of void.

 drivers/Makefile                    |    2 
 drivers/input/gameport/gameport.c   |   39 ++++++++++++++++++
 drivers/input/joystick/a3d.c        |   44 ++++++++++++++-------
 drivers/input/joystick/adi.c        |   63 ++++++++++++++----------------
 drivers/input/joystick/analog.c     |   52 +++++++++++++++---------
 drivers/input/joystick/cobra.c      |   42 ++++++++++++--------
 drivers/input/joystick/gf2k.c       |   42 +++++++++++++-------
 drivers/input/joystick/grip.c       |   61 +++++++++++++----------------
 drivers/input/joystick/grip_mp.c    |   56 +++++++++++++++++---------
 drivers/input/joystick/guillemot.c  |   53 ++++++++++++++-----------
 drivers/input/joystick/interact.c   |   32 +++++++++++----
 drivers/input/joystick/joydump.c    |   20 ++++++---
 drivers/input/joystick/sidewinder.c |   75 +++++++++++++++++++++++++-----------
 drivers/input/joystick/tmdc.c       |   53 +++++++++++++------------
 include/linux/gameport.h            |    6 +-
 15 files changed, 407 insertions(+), 233 deletions(-)

===================================================================

drivers/Makefile +1 -1
diff -Nru a/drivers/Makefile b/drivers/Makefile
@@ -47,8 +47,8 @@
 obj-$(CONFIG_TC)		+= tc/
 obj-$(CONFIG_USB)		+= usb/
 obj-$(CONFIG_USB_GADGET)	+= usb/gadget/
-obj-$(CONFIG_INPUT)		+= input/
 obj-$(CONFIG_GAMEPORT)		+= input/gameport/
+obj-$(CONFIG_INPUT)		+= input/
 obj-$(CONFIG_I2O)		+= message/
 obj-$(CONFIG_I2C)		+= i2c/
 obj-$(CONFIG_W1)		+= w1/
drivers/input/gameport/gameport.c +39 -0
diff -Nru a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
@@ -37,6 +37,10 @@
 static LIST_HEAD(gameport_list);
 static LIST_HEAD(gameport_driver_list);
 
+static struct bus_type gameport_bus = {
+	.name =	"gameport",
+};
+
 #ifdef __i386__
 
 #define DELTA(x,y)      ((y)-(x)+((y)<(x)?1193182/HZ:0))
@@ -146,6 +150,21 @@
 	gameport_find_driver(gameport);
 }
 
+/*
+ * Gameport driver operations
+ */
+
+static ssize_t gameport_driver_show_description(struct device_driver *drv, char *buf)
+{
+	struct gameport_driver *driver = to_gameport_driver(drv);
+	return sprintf(buf, "%s\n", driver->description ? driver->description : "(none)");
+}
+
+static struct driver_attribute gameport_driver_attrs[] = {
+	__ATTR(description, S_IRUGO, gameport_driver_show_description, NULL),
+	__ATTR_NULL
+};
+
 void gameport_unregister_port(struct gameport *gameport)
 {
 	list_del_init(&gameport->node);
@@ -159,6 +178,9 @@
 {
 	struct gameport *gameport;
 
+	drv->driver.bus = &gameport_bus;
+	driver_register(&drv->driver);
+
 	list_add_tail(&drv->node, &gameport_driver_list);
 	list_for_each_entry(gameport, &gameport_list, node)
 		if (!gameport->drv)
@@ -175,6 +197,7 @@
 			drv->disconnect(gameport);
 		gameport_find_driver(gameport);
 	}
+	driver_unregister(&drv->driver);
 }
 
 int gameport_open(struct gameport *gameport, struct gameport_driver *drv, int mode)
@@ -201,3 +224,19 @@
 	if (gameport->close)
 		gameport->close(gameport);
 }
+
+static int __init gameport_init(void)
+{
+	gameport_bus.drv_attrs = gameport_driver_attrs;
+	bus_register(&gameport_bus);
+
+	return 0;
+}
+
+static void __exit gameport_exit(void)
+{
+	bus_unregister(&gameport_bus);
+}
+
+module_init(gameport_init);
+module_exit(gameport_exit);
drivers/input/joystick/a3d.c +31 -13

143 lines not on this page · raw message

drivers/input/joystick/adi.c +30 -33

124 lines not on this page · raw message

drivers/input/joystick/analog.c +32 -20

121 lines not on this page · raw message

drivers/input/joystick/cobra.c +26 -16

100 lines not on this page · raw message

drivers/input/joystick/gf2k.c +29 -13

103 lines not on this page · raw message

drivers/input/joystick/grip.c +29 -32

122 lines not on this page · raw message

drivers/input/joystick/grip_mp.c +36 -20

134 lines not on this page · raw message

drivers/input/joystick/guillemot.c +31 -22

126 lines not on this page · raw message

drivers/input/joystick/interact.c +23 -9
diff -Nru a/drivers/input/joystick/interact.c b/drivers/input/joystick/interact.c
@@ -39,8 +39,10 @@
 #include <linux/gameport.h>
 #include <linux/input.h>
 
+#define DRIVER_DESC	"InterAct digital joystick driver"
+
 MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");
-MODULE_DESCRIPTION("InterAct digital joystick driver");
+MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_LICENSE("GPL");
 
 #define INTERACT_MAX_START	400	/* 400 us */
@@ -189,6 +191,7 @@
 static int interact_open(struct input_dev *dev)
 {
 	struct interact *interact = dev->private;
+
 	if (!interact->used++)
 		mod_timer(&interact->timer, jiffies + INTERACT_REFRESH_TIME);
 	return 0;
@@ -201,6 +204,7 @@
 static void interact_close(struct input_dev *dev)
 {
 	struct interact *interact = dev->private;
+
 	if (!--interact->used)
 		del_timer(&interact->timer);
 }
@@ -209,15 +213,15 @@
  * interact_connect() probes for InterAct joysticks.
  */
 
-static void interact_connect(struct gameport *gameport, struct gameport_driver *drv)
+static int interact_connect(struct gameport *gameport, struct gameport_driver *drv)
 {
 	struct interact *interact;
 	__u32 data[3];
 	int i, t;
+	int err;
 
-	if (!(interact = kmalloc(sizeof(struct interact), GFP_KERNEL)))
-		return;
-	memset(interact, 0, sizeof(struct interact));
+	if (!(interact = kcalloc(1, sizeof(struct interact), GFP_KERNEL)))
+		return -ENOMEM;
 
 	gameport->private = interact;
 
@@ -226,12 +230,14 @@
 	interact->timer.data = (long) interact;
 	interact->timer.function = interact_timer;
 
-	if (gameport_open(gameport, drv, GAMEPORT_MODE_RAW))
+	err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW);
+	if (err)
 		goto fail1;
 
 	i = interact_read_packet(gameport, INTERACT_MAX_LENGTH * 2, data);
 
 	if (i != 32 || (data[0] >> 24) != 0x0c || (data[1] >> 24) != 0x02) {
+		err = -ENODEV;
 		goto fail2;
 	}
 
@@ -242,6 +248,7 @@
 	if (!interact_type[i].length) {
 		printk(KERN_WARNING "interact.c: Unknown joystick on %s. [len %d d0 %08x d1 %08x i2 %08x]\n",
 			gameport->phys, i, data[0], data[1], data[2]);
+		err = -ENODEV;
 		goto fail2;
 	}
 
@@ -281,22 +288,29 @@
 	printk(KERN_INFO "input: %s on %s\n",
 		interact_type[interact->type].name, gameport->phys);
 
-	return;
+	return 0;
+
 fail2:	gameport_close(gameport);
 fail1:  kfree(interact);
+	return err;
 }
 
 static void interact_disconnect(struct gameport *gameport)
 {
 	struct interact *interact = gameport->private;
+
 	input_unregister_device(&interact->dev);
 	gameport_close(gameport);
 	kfree(interact);
 }
 
 static struct gameport_driver interact_drv = {
-	.connect =	interact_connect,
-	.disconnect =	interact_disconnect,
+	.driver		= {
+		.name	= "interact",
+	},
+	.description	= DRIVER_DESC,
+	.connect	= interact_connect,
+	.disconnect	= interact_disconnect,
 };
 
 static int __init interact_init(void)
drivers/input/joystick/joydump.c +14 -6
diff -Nru a/drivers/input/joystick/joydump.c b/drivers/input/joystick/joydump.c
@@ -35,8 +35,10 @@
 #include <linux/delay.h>
 #include <linux/init.h>
 
+#define DRIVER_DESC	"Gameport data dumper module"
+
 MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");
-MODULE_DESCRIPTION("Gameport data dumper module");
+MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_LICENSE("GPL");
 
 #define BUF_SIZE 256
@@ -46,7 +48,7 @@
 	unsigned char data;
 };
 
-static void __devinit joydump_connect(struct gameport *gameport, struct gameport_driver *drv)
+static int joydump_connect(struct gameport *gameport, struct gameport_driver *drv)
 {
 	struct joydump *buf;	/* all entries */
 	struct joydump *dump, *prev;	/* one entry each */
@@ -67,7 +69,7 @@
 
 			printk(KERN_INFO "joydump: | Cooked not available either. Failing.      |\n");
 			printk(KERN_INFO "joydump: `-------------------- END -------------------'\n");
-			return;
+			return -ENODEV;
 		}
 
 		gameport_cooked_read(gameport, axes, &buttons);
@@ -140,16 +142,22 @@
 
 jd_end:
 	printk(KERN_INFO "joydump: `-------------------- END -------------------'\n");
+
+	return 0;
 }
 
-static void __devexit joydump_disconnect(struct gameport *gameport)
+static void joydump_disconnect(struct gameport *gameport)
 {
 	gameport_close(gameport);
 }
 
 static struct gameport_driver joydump_drv = {
-	.connect =	joydump_connect,
-	.disconnect =	joydump_disconnect,
+	.driver		= {
+		.name	= "joydump",
+	},
+	.description	= DRIVER_DESC,
+	.connect	= joydump_connect,
+	.disconnect	= joydump_disconnect,
 };
 
 static int __init joydump_init(void)
drivers/input/joystick/sidewinder.c +53 -22

218 lines not on this page · raw message

drivers/input/joystick/tmdc.c +29 -24

110 lines not on this page · raw message

include/linux/gameport.h +4 -2
diff -Nru a/include/linux/gameport.h b/include/linux/gameport.h
@@ -45,13 +45,15 @@
 struct gameport_driver {
 
 	void *private;
-	char *name;
+	char *description;
 
-	void (*connect)(struct gameport *, struct gameport_driver *drv);
+	int (*connect)(struct gameport *, struct gameport_driver *drv);
 	void (*disconnect)(struct gameport *);
 
+	struct device_driver driver;
 	struct list_head node;
 };
+#define to_gameport_driver(d)	container_of(d, struct gameport_driver, driver)
 
 int gameport_open(struct gameport *gameport, struct gameport_driver *drv, int mode);
 void gameport_close(struct gameport *gameport);

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click

#9 lore raw

PATCH 9/10 Gameport: complete sysfs integration

===================================================================

[email protected], 2005-02-11 01:21:32-05:00, [email protected]
Input: complete gameport sysfs integration, ports are now
devices in driver model. Implemented similarly to serio.

 drivers/input/gameport/gameport.c |  586 ++++++++++++++++++++++++++++++++++----
 include/linux/gameport.h          |   64 ++--
 2 files changed, 579 insertions(+), 71 deletions(-)

===================================================================

drivers/input/gameport/gameport.c +536 -50
diff -Nru a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
@@ -2,6 +2,7 @@
  * Generic gameport layer
  *
  * Copyright (c) 1999-2002 Vojtech Pavlik
+ * Copyright (c) 2005 Dmitry Torokhov
  */
 
 /*
@@ -10,22 +11,27 @@
  * the Free Software Foundation.
  */
 
-#include <asm/io.h>
+#include <linux/stddef.h>
 #include <linux/module.h>
 #include <linux/ioport.h>
 #include <linux/init.h>
 #include <linux/gameport.h>
+#include <linux/wait.h>
+#include <linux/completion.h>
+#include <linux/sched.h>
+#include <linux/smp_lock.h>
 #include <linux/slab.h>
-#include <linux/stddef.h>
 #include <linux/delay.h>
 
+/*#include <asm/io.h>*/
+
 MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");
 MODULE_DESCRIPTION("Generic gameport layer");
 MODULE_LICENSE("GPL");
 
-EXPORT_SYMBOL(gameport_register_port);
+EXPORT_SYMBOL(__gameport_register_port);
 EXPORT_SYMBOL(gameport_unregister_port);
-EXPORT_SYMBOL(gameport_register_driver);
+EXPORT_SYMBOL(__gameport_register_driver);
 EXPORT_SYMBOL(gameport_unregister_driver);
 EXPORT_SYMBOL(gameport_open);
 EXPORT_SYMBOL(gameport_close);
@@ -34,13 +40,23 @@
 EXPORT_SYMBOL(gameport_set_name);
 EXPORT_SYMBOL(gameport_set_phys);
 
+/*
+ * gameport_sem protects entire gameport subsystem and is taken
+ * every time gameport port or driver registrered or unregistered.
+ */
+static DECLARE_MUTEX(gameport_sem);
+
 static LIST_HEAD(gameport_list);
-static LIST_HEAD(gameport_driver_list);
 
 static struct bus_type gameport_bus = {
 	.name =	"gameport",
 };
 
+static void gameport_add_port(struct gameport *gameport);
+static void gameport_destroy_port(struct gameport *gameport);
+static void gameport_reconnect_port(struct gameport *gameport);
+static void gameport_disconnect_port(struct gameport *gameport);
+
 #ifdef __i386__
 
 #define DELTA(x,y)      ((y)-(x)+((y)<(x)?1193182/HZ:0))
@@ -106,21 +122,325 @@
 #endif
 }
 
+
+/*
+ * Basic gameport -> driver core mappings
+ */
+
+static void gameport_bind_driver(struct gameport *gameport, struct gameport_driver *drv)
+{
+	down_write(&gameport_bus.subsys.rwsem);
+
+	gameport->dev.driver = &drv->driver;
+	if (drv->connect(gameport, drv)) {
+		gameport->dev.driver = NULL;
+		goto out;
+	}
+	device_bind_driver(&gameport->dev);
+out:
+	up_write(&gameport_bus.subsys.rwsem);
+}
+
+static void gameport_release_driver(struct gameport *gameport)
+{
+	down_write(&gameport_bus.subsys.rwsem);
+	device_release_driver(&gameport->dev);
+	up_write(&gameport_bus.subsys.rwsem);
+}
+
 static void gameport_find_driver(struct gameport *gameport)
 {
-        struct gameport_driver *drv;
+	down_write(&gameport_bus.subsys.rwsem);
+	device_attach(&gameport->dev);
+	up_write(&gameport_bus.subsys.rwsem);
+}
+
+
+/*
+ * Gameport event processing.
+ */
+
+enum gameport_event_type {
+	GAMEPORT_RESCAN,
+	GAMEPORT_RECONNECT,
+	GAMEPORT_REGISTER_PORT,
+	GAMEPORT_REGISTER_DRIVER,
+};
+
+struct gameport_event {
+	enum gameport_event_type type;
+	void *object;
+	struct module *owner;
+	struct list_head node;
+};
+
+static DEFINE_SPINLOCK(gameport_event_lock);	/* protects gameport_event_list */
+static LIST_HEAD(gameport_event_list);
+static DECLARE_WAIT_QUEUE_HEAD(gameport_wait);
+static DECLARE_COMPLETION(gameport_exited);
+static int gameport_pid;
+
+static void gameport_queue_event(void *object, struct module *owner,
+			      enum gameport_event_type event_type)
+{
+	unsigned long flags;
+	struct gameport_event *event;
+
+	spin_lock_irqsave(&gameport_event_lock, flags);
 
-        list_for_each_entry(drv, &gameport_driver_list, node) {
-		if (gameport->drv)
+	/*
+ 	 * Scan event list for the other events for the same gameport port,
+	 * starting with the most recent one. If event is the same we
+	 * do not need add new one. If event is of different type we
+	 * need to add this event and should not look further because
+	 * we need to preseve sequence of distinct events.
+ 	 */
+	list_for_each_entry_reverse(event, &gameport_event_list, node) {
+		if (event->object == object) {
+			if (event->type == event_type)
+				goto out;
 			break;
-               	drv->connect(gameport, drv);
-        }
+		}
+	}
+
+	if ((event = kmalloc(sizeof(struct gameport_event), GFP_ATOMIC))) {
+		if (!try_module_get(owner)) {
+			printk(KERN_WARNING "gameport: Can't get module reference, dropping event %d\n", event_type);
+			goto out;
+		}
+
+		event->type = event_type;
+		event->object = object;
+		event->owner = owner;
+
+		list_add_tail(&event->node, &gameport_event_list);
+		wake_up(&gameport_wait);
+	} else {
+		printk(KERN_ERR "gameport: Not enough memory to queue event %d\n", event_type);
+	}
+out:
+	spin_unlock_irqrestore(&gameport_event_lock, flags);
 }
 
-void gameport_rescan(struct gameport *gameport)
+static void gameport_free_event(struct gameport_event *event)
 {
-	gameport_close(gameport);
-	gameport_find_driver(gameport);
+	module_put(event->owner);
+	kfree(event);
+}
+
+static void gameport_remove_duplicate_events(struct gameport_event *event)
+{
+	struct list_head *node, *next;
+	struct gameport_event *e;
+	unsigned long flags;
+
+	spin_lock_irqsave(&gameport_event_lock, flags);
+
+	list_for_each_safe(node, next, &gameport_event_list) {
+		e = list_entry(node, struct gameport_event, node);
+		if (event->object == e->object) {
+			/*
+			 * If this event is of different type we should not
+			 * look further - we only suppress duplicate events
+			 * that were sent back-to-back.
+			 */
+			if (event->type != e->type)
+				break;
+
+			list_del_init(node);
+			gameport_free_event(e);
+		}
+	}
+
+	spin_unlock_irqrestore(&gameport_event_lock, flags);
+}
+
+
+static struct gameport_event *gameport_get_event(void)
+{
+	struct gameport_event *event;
+	struct list_head *node;
+	unsigned long flags;
+
+	spin_lock_irqsave(&gameport_event_lock, flags);
+
+	if (list_empty(&gameport_event_list)) {
+		spin_unlock_irqrestore(&gameport_event_lock, flags);
+		return NULL;
+	}
+
+	node = gameport_event_list.next;
+	event = list_entry(node, struct gameport_event, node);
+	list_del_init(node);
+
+	spin_unlock_irqrestore(&gameport_event_lock, flags);
+
+	return event;
+}
+
+static void gameport_handle_events(void)
+{
+	struct gameport_event *event;
+	struct gameport_driver *gameport_drv;
+
+	down(&gameport_sem);
+
+	while ((event = gameport_get_event())) {
+
+		switch (event->type) {
+			case GAMEPORT_REGISTER_PORT:
+				gameport_add_port(event->object);
+				break;
+
+			case GAMEPORT_RECONNECT:
+				gameport_reconnect_port(event->object);
+				break;
+
+			case GAMEPORT_RESCAN:
+				gameport_disconnect_port(event->object);
+				gameport_find_driver(event->object);
+				break;
+
+			case GAMEPORT_REGISTER_DRIVER:
+				gameport_drv = event->object;
+				driver_register(&gameport_drv->driver);
+				break;
+
+			default:
+				break;
+		}
+
+		gameport_remove_duplicate_events(event);
+		gameport_free_event(event);
+	}
+
+	up(&gameport_sem);
+}
+
+/*
+ * Remove all events that have been submitted for a given gameport port.
+ */
+static void gameport_remove_pending_events(struct gameport *gameport)
+{
+	struct list_head *node, *next;
+	struct gameport_event *event;
+	unsigned long flags;
+
+	spin_lock_irqsave(&gameport_event_lock, flags);
+
+	list_for_each_safe(node, next, &gameport_event_list) {
+		event = list_entry(node, struct gameport_event, node);
+		if (event->object == gameport) {
+			list_del_init(node);
+			gameport_free_event(event);
+		}
+	}
+
+	spin_unlock_irqrestore(&gameport_event_lock, flags);
+}
+
+/*
+ * Destroy child gameport port (if any) that has not been fully registered yet.
+ *
+ * Note that we rely on the fact that port can have only one child and therefore
+ * only one child registration request can be pending. Additionally, children
+ * are registered by driver's connect() handler so there can't be a grandchild
+ * pending registration together with a child.
+ */
+static struct gameport *gameport_get_pending_child(struct gameport *parent)
+{
+	struct gameport_event *event;
+	struct gameport *gameport, *child = NULL;
+	unsigned long flags;
+
+	spin_lock_irqsave(&gameport_event_lock, flags);
+
+	list_for_each_entry(event, &gameport_event_list, node) {
+		if (event->type == GAMEPORT_REGISTER_PORT) {
+			gameport = event->object;
+			if (gameport->parent == parent) {
+				child = gameport;
+				break;
+			}
+		}
+	}
+
+	spin_unlock_irqrestore(&gameport_event_lock, flags);
+	return child;
+}
+
+static int gameport_thread(void *nothing)
+{
+	lock_kernel();
+	daemonize("kgameportd");
+	allow_signal(SIGTERM);
+
+	do {
+		gameport_handle_events();
+		wait_event_interruptible(gameport_wait, !list_empty(&gameport_event_list));
+		try_to_freeze(PF_FREEZE);
+	} while (!signal_pending(current));
+
+	printk(KERN_DEBUG "gameport: kgameportd exiting\n");
+
+	unlock_kernel();
+	complete_and_exit(&gameport_exited, 0);
+}
+
+
+/*
+ * Gameport port operations
+ */
+
+static ssize_t gameport_show_description(struct device *dev, char *buf)
+{
+	struct gameport *gameport = to_gameport_port(dev);
+	return sprintf(buf, "%s\n", gameport->name);
+}
+
+static ssize_t gameport_rebind_driver(struct device *dev, const char *buf, size_t count)
+{
+	struct gameport *gameport = to_gameport_port(dev);
+	struct device_driver *drv;
+	int retval;
+
+	retval = down_interruptible(&gameport_sem);
+	if (retval)
+		return retval;
+
+	retval = count;
+	if (!strncmp(buf, "none", count)) {
+		gameport_disconnect_port(gameport);
+	} else if (!strncmp(buf, "reconnect", count)) {
+		gameport_reconnect_port(gameport);
+	} else if (!strncmp(buf, "rescan", count)) {
+		gameport_disconnect_port(gameport);
+		gameport_find_driver(gameport);
+	} else if ((drv = driver_find(buf, &gameport_bus)) != NULL) {
+		gameport_disconnect_port(gameport);
+		gameport_bind_driver(gameport, to_gameport_driver(drv));
+		put_driver(drv);
+	} else {
+		retval = -EINVAL;
+	}
+
+	up(&gameport_sem);
+
+	return retval;
+}
+
+static struct device_attribute gameport_device_attrs[] = {
+	__ATTR(description, S_IRUGO, gameport_show_description, NULL),
+	__ATTR(drvctl, S_IWUSR, NULL, gameport_rebind_driver),
+	__ATTR_NULL
+};
+
+static void gameport_release_port(struct device *dev)
+{
+	struct gameport *gameport = to_gameport_port(dev);
+
+	kfree(gameport);
+	module_put(THIS_MODULE);
 }
 
 void gameport_set_phys(struct gameport *gameport, const char *fmt, ...)
@@ -128,29 +448,162 @@
 	va_list args;
 
 	va_start(args, fmt);
-	gameport->phys = gameport->phys_buf;
-	vsnprintf(gameport->phys_buf, sizeof(gameport->phys_buf), fmt, args);
+	vsnprintf(gameport->phys, sizeof(gameport->phys), fmt, args);
 	va_end(args);
 }
 
-void gameport_register_port(struct gameport *gameport)
+/*
+ * Prepare gameport port for registration.
+ */
+static void gameport_init_port(struct gameport *gameport)
 {
-	list_add_tail(&gameport->node, &gameport_list);
+	static atomic_t gameport_no = ATOMIC_INIT(0);
+
+	__module_get(THIS_MODULE);
+
+	init_MUTEX(&gameport->drv_sem);
+	device_initialize(&gameport->dev);
+	snprintf(gameport->dev.bus_id, sizeof(gameport->dev.bus_id),
+		 "gameport%lu", (unsigned long)atomic_inc_return(&gameport_no) - 1);
+	gameport->dev.bus = &gameport_bus;
+	gameport->dev.release = gameport_release_port;
+	if (gameport->parent)
+		gameport->dev.parent = &gameport->parent->dev;
+}
+
+/*
+ * Complete gameport port registration.
+ * Driver core will attempt to find appropriate driver for the port.
+ */
+static void gameport_add_port(struct gameport *gameport)
+{
+	if (gameport->parent)
+		gameport->parent->child = gameport;
+
 	gameport->speed = gameport_measure_speed(gameport);
 
-	if (gameport->dyn_alloc) {
-		if (gameport->io)
-			printk(KERN_INFO "gameport: %s is %s, io %#x, speed %d kHz\n",
-				gameport->name, gameport->phys, gameport->io, gameport->speed);
-		else
-			printk(KERN_INFO "gameport: %s is %s, speed %d kHz\n",
-				gameport->name, gameport->phys, gameport->speed);
+	list_add_tail(&gameport->node, &gameport_list);
+
+	if (gameport->io)
+		printk(KERN_INFO "gameport: %s is %s, io %#x, speed %dkHz\n",
+			gameport->name, gameport->phys, gameport->io, gameport->speed);
+	else
+		printk(KERN_INFO "gameport: %s is %s, speed %dkHz\n",
+			gameport->name, gameport->phys, gameport->speed);
+
+	device_add(&gameport->dev);
+	gameport->registered = 1;
+}
+
+/*
+ * gameport_destroy_port() completes deregistration process and removes
+ * port from the system
+ */
+static void gameport_destroy_port(struct gameport *gameport)
+{
+	struct gameport *child;
+
+	child = gameport_get_pending_child(gameport);
+	if (child) {
+		gameport_remove_pending_events(child);
+		put_device(&child->dev);
 	}
 
-	gameport_find_driver(gameport);
+	if (gameport->parent) {
+		gameport->parent->child = NULL;
+		gameport->parent = NULL;
+	}
+
+	if (gameport->registered) {
+		device_del(&gameport->dev);
+		list_del_init(&gameport->node);
+		gameport->registered = 0;
+	}
+
+	gameport_remove_pending_events(gameport);
+	put_device(&gameport->dev);
 }
 
 /*
+ * Reconnect gameport port and all its children (re-initialize attached devices)
+ */
+static void gameport_reconnect_port(struct gameport *gameport)
+{
+	do {
+		if (!gameport->drv || !gameport->drv->reconnect || gameport->drv->reconnect(gameport)) {
+			gameport_disconnect_port(gameport);
+			gameport_find_driver(gameport);
+			/* Ok, old children are now gone, we are done */
+			break;
+		}
+		gameport = gameport->child;
+	} while (gameport);
+}
+
+/*
+ * gameport_disconnect_port() unbinds a port from its driver. As a side effect
+ * all child ports are unbound and destroyed.
+ */
+static void gameport_disconnect_port(struct gameport *gameport)
+{
+	struct gameport *s, *parent;
+
+	if (gameport->child) {
+		/*
+		 * Children ports should be disconnected and destroyed
+		 * first, staring with the leaf one, since we don't want
+		 * to do recursion
+		 */
+		for (s = gameport; s->child; s = s->child)
+			/* empty */;
+
+		do {
+			parent = s->parent;
+
+			gameport_release_driver(s);
+			gameport_destroy_port(s);
+		} while ((s = parent) != gameport);
+	}
+
+	/*
+	 * Ok, no children left, now disconnect this port
+	 */
+	gameport_release_driver(gameport);
+}
+
+void gameport_rescan(struct gameport *gameport)
+{
+	gameport_queue_event(gameport, NULL, GAMEPORT_RESCAN);
+}
+
+void gameport_reconnect(struct gameport *gameport)
+{
+	gameport_queue_event(gameport, NULL, GAMEPORT_RECONNECT);
+}
+
+/*
+ * Submits register request to kgameportd for subsequent execution.
+ * Note that port registration is always asynchronous.
+ */
+void __gameport_register_port(struct gameport *gameport, struct module *owner)
+{
+	gameport_init_port(gameport);
+	gameport_queue_event(gameport, owner, GAMEPORT_REGISTER_PORT);
+}
+
+/*
+ * Synchronously unregisters gameport port.
+ */
+void gameport_unregister_port(struct gameport *gameport)
+{
+	down(&gameport_sem);
+	gameport_disconnect_port(gameport);
+	gameport_destroy_port(gameport);
+	up(&gameport_sem);
+}
+
+
+/*
  * Gameport driver operations
  */
 
@@ -165,69 +618,100 @@
 	__ATTR_NULL
 };
 
-void gameport_unregister_port(struct gameport *gameport)
+static int gameport_driver_probe(struct device *dev)
 {
-	list_del_init(&gameport->node);
-	if (gameport->drv)
-		gameport->drv->disconnect(gameport);
-	if (gameport->dyn_alloc)
-		kfree(gameport);
+	struct gameport *gameport = to_gameport_port(dev);
+	struct gameport_driver *drv = to_gameport_driver(dev->driver);
+
+	drv->connect(gameport, drv);
+	return gameport->drv ? 0 : -ENODEV;
 }
 
-void gameport_register_driver(struct gameport_driver *drv)
+static int gameport_driver_remove(struct device *dev)
 {
-	struct gameport *gameport;
+	struct gameport *gameport = to_gameport_port(dev);
+	struct gameport_driver *drv = to_gameport_driver(dev->driver);
 
-	drv->driver.bus = &gameport_bus;
-	driver_register(&drv->driver);
+	drv->disconnect(gameport);
+	return 0;
+}
 
-	list_add_tail(&drv->node, &gameport_driver_list);
-	list_for_each_entry(gameport, &gameport_list, node)
-		if (!gameport->drv)
-			drv->connect(gameport, drv);
+void __gameport_register_driver(struct gameport_driver *drv, struct module *owner)
+{
+	drv->driver.bus = &gameport_bus;
+	drv->driver.probe = gameport_driver_probe;
+	drv->driver.remove = gameport_driver_remove;
+	gameport_queue_event(drv, owner, GAMEPORT_REGISTER_DRIVER);
 }
 
 void gameport_unregister_driver(struct gameport_driver *drv)
 {
 	struct gameport *gameport;
 
-	list_del_init(&drv->node);
+	down(&gameport_sem);
+	drv->ignore = 1;	/* so gameport_find_driver ignores it */
+
+start_over:
 	list_for_each_entry(gameport, &gameport_list, node) {
-		if (gameport->drv == drv)
-			drv->disconnect(gameport);
-		gameport_find_driver(gameport);
+		if (gameport->drv == drv) {
+			gameport_disconnect_port(gameport);
+			gameport_find_driver(gameport);
+			/* we could've deleted some ports, restart */
+			goto start_over;
+		}
 	}
+
 	driver_unregister(&drv->driver);
+	up(&gameport_sem);
+}
+
+static int gameport_bus_match(struct device *dev, struct device_driver *drv)
+{
+	struct gameport_driver *gameport_drv = to_gameport_driver(drv);
+
+	return !gameport_drv->ignore;
+}
+
+static void gameport_set_drv(struct gameport *gameport, struct gameport_driver *drv)
+{
+	down(&gameport->drv_sem);
+	gameport->drv = drv;
+	up(&gameport->drv_sem);
 }
 
 int gameport_open(struct gameport *gameport, struct gameport_driver *drv, int mode)
 {
+
 	if (gameport->open) {
-		if (gameport->open(gameport, mode))
+		if (gameport->open(gameport, mode)) {
 			return -1;
+		}
 	} else {
 		if (mode != GAMEPORT_MODE_RAW)
 			return -1;
 	}
 
-	if (gameport->drv)
-		return -1;
-
-	gameport->drv = drv;
-
+	gameport_set_drv(gameport, drv);
 	return 0;
 }
 
 void gameport_close(struct gameport *gameport)
 {
-	gameport->drv = NULL;
+	gameport_set_drv(gameport, NULL);
 	if (gameport->close)
 		gameport->close(gameport);
 }
 
 static int __init gameport_init(void)
 {
+	if (!(gameport_pid = kernel_thread(gameport_thread, NULL, CLONE_KERNEL))) {
+		printk(KERN_ERR "gameport: Failed to start kgameportd\n");
+		return -1;
+	}
+
+	gameport_bus.dev_attrs = gameport_device_attrs;
 	gameport_bus.drv_attrs = gameport_driver_attrs;
+	gameport_bus.match = gameport_bus_match;
 	bus_register(&gameport_bus);
 
 	return 0;
@@ -236,6 +720,8 @@
 static void __exit gameport_exit(void)
 {
 	bus_unregister(&gameport_bus);
+	kill_proc(gameport_pid, SIGTERM, 1);
+	wait_for_completion(&gameport_exited);
 }
 
 module_init(gameport_init);
include/linux/gameport.h +43 -21

142 lines not on this page · raw message

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click

#10 lore raw

PATCH 10/10 Gameport: replace ->private with gameport_get/set_drvdata

===================================================================

[email protected], 2005-02-11 01:23:40-05:00, [email protected]
Input: remove gameport->private in favor of using driver-specific data
in device structure, add gameport_get/set_drvdata to access it.

 drivers/input/joystick/a3d.c        |   10 ++++++----
 drivers/input/joystick/adi.c        |    7 ++++---
 drivers/input/joystick/analog.c     |    7 +++++--
 drivers/input/joystick/cobra.c      |   10 ++++++----
 drivers/input/joystick/gf2k.c       |   10 ++++++----
 drivers/input/joystick/grip.c       |   10 ++++++----
 drivers/input/joystick/grip_mp.c    |    9 ++++++---
 drivers/input/joystick/guillemot.c  |    9 +++++----
 drivers/input/joystick/interact.c   |   10 ++++++----
 drivers/input/joystick/sidewinder.c |   10 ++++++----
 drivers/input/joystick/tmdc.c       |   10 ++++++----
 include/linux/gameport.h            |   15 ++++++++++++++-
 12 files changed, 76 insertions(+), 41 deletions(-)

===================================================================

drivers/input/joystick/a3d.c +6 -4
diff -Nru a/drivers/input/joystick/a3d.c b/drivers/input/joystick/a3d.c
@@ -277,13 +277,13 @@
 	if (!(a3d = kcalloc(1, sizeof(struct a3d), GFP_KERNEL)))
 		return -ENOMEM;
 
-	gameport->private = a3d;
-
 	a3d->gameport = gameport;
 	init_timer(&a3d->timer);
 	a3d->timer.data = (long) a3d;
 	a3d->timer.function = a3d_timer;
 
+	gameport_set_drvdata(gameport, a3d);
+
 	err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW);
 	if (err)
 		goto fail1;
@@ -379,13 +379,14 @@
 	return 0;
 
 fail2:	gameport_close(gameport);
-fail1:  kfree(a3d);
+fail1:  gameport_set_drvdata(gameport, NULL);
+	kfree(a3d);
 	return err;
 }
 
 static void a3d_disconnect(struct gameport *gameport)
 {
-	struct a3d *a3d = gameport->private;
+	struct a3d *a3d = gameport_get_drvdata(gameport);
 
 	input_unregister_device(&a3d->dev);
 	if (a3d->adc) {
@@ -393,6 +394,7 @@
 		a3d->adc = NULL;
 	}
 	gameport_close(gameport);
+	gameport_set_drvdata(gameport, NULL);
 	kfree(a3d);
 }
 
drivers/input/joystick/adi.c +4 -3
diff -Nru a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
@@ -474,13 +474,13 @@
 	if (!(port = kcalloc(1, sizeof(struct adi_port), GFP_KERNEL)))
 		return -ENOMEM;
 
-	gameport->private = port;
-
 	port->gameport = gameport;
 	init_timer(&port->timer);
 	port->timer.data = (long) port;
 	port->timer.function = adi_timer;
 
+	gameport_set_drvdata(gameport, port);
+
 	err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW);
 	if (err) {
 		kfree(port);
@@ -524,12 +524,13 @@
 static void adi_disconnect(struct gameport *gameport)
 {
 	int i;
-	struct adi_port *port = gameport->private;
+	struct adi_port *port = gameport_get_drvdata(gameport);
 
 	for (i = 0; i < 2; i++)
 		if (port->adi[i].length > 0)
 			input_unregister_device(&port->adi[i].dev);
 	gameport_close(gameport);
+	gameport_set_drvdata(gameport, NULL);
 	kfree(port);
 }
 
drivers/input/joystick/analog.c +5 -2
diff -Nru a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c
@@ -593,12 +593,13 @@
 {
 	int i, t, u, v;
 
-	gameport->private = port;
 	port->gameport = gameport;
 	init_timer(&port->timer);
 	port->timer.data = (long) port;
 	port->timer.function = analog_timer;
 
+	gameport_set_drvdata(gameport, port);
+
 	if (!gameport_open(gameport, drv, GAMEPORT_MODE_RAW)) {
 
 		analog_calibrate_timer(port);
@@ -672,6 +673,7 @@
 	err = analog_init_masks(port);
 	if (err) {
 		gameport_close(gameport);
+		gameport_set_drvdata(gameport, NULL);
 		kfree(port);
 		return err;
 	}
@@ -686,12 +688,13 @@
 static void analog_disconnect(struct gameport *gameport)
 {
 	int i;
-	struct analog_port *port = gameport->private;
+	struct analog_port *port = gameport_get_drvdata(gameport);
 
 	for (i = 0; i < 2; i++)
 		if (port->analog[i].mask)
 			input_unregister_device(&port->analog[i].dev);
 	gameport_close(gameport);
+	gameport_set_drvdata(gameport, NULL);
 	printk(KERN_INFO "analog.c: %d out of %d reads (%d%%) on %s failed\n",
 		port->bads, port->reads, port->reads ? (port->bads * 100 / port->reads) : 0,
 		port->gameport->phys);
drivers/input/joystick/cobra.c +6 -4
diff -Nru a/drivers/input/joystick/cobra.c b/drivers/input/joystick/cobra.c
@@ -170,13 +170,13 @@
 	if (!(cobra = kcalloc(1, sizeof(struct cobra), GFP_KERNEL)))
 		return -ENOMEM;
 
-	gameport->private = cobra;
-
 	cobra->gameport = gameport;
 	init_timer(&cobra->timer);
 	cobra->timer.data = (long) cobra;
 	cobra->timer.function = cobra_timer;
 
+	gameport_set_drvdata(gameport, cobra);
+
 	err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW);
 	if (err)
 		goto fail1;
@@ -226,19 +226,21 @@
 	return 0;
 
 fail2:	gameport_close(gameport);
-fail1:	kfree(cobra);
+fail1:	gameport_set_drvdata(gameport, NULL);
+	kfree(cobra);
 	return err;
 }
 
 static void cobra_disconnect(struct gameport *gameport)
 {
+	struct cobra *cobra = gameport_get_drvdata(gameport);
 	int i;
-	struct cobra *cobra = gameport->private;
 
 	for (i = 0; i < 2; i++)
 		if ((cobra->exists >> i) & 1)
 			input_unregister_device(cobra->dev + i);
 	gameport_close(gameport);
+	gameport_set_drvdata(gameport, NULL);
 	kfree(cobra);
 }
 
drivers/input/joystick/gf2k.c +6 -4
diff -Nru a/drivers/input/joystick/gf2k.c b/drivers/input/joystick/gf2k.c
@@ -249,13 +249,13 @@
 	if (!(gf2k = kcalloc(1, sizeof(struct gf2k), GFP_KERNEL)))
 		return -ENOMEM;
 
-	gameport->private = gf2k;
-
 	gf2k->gameport = gameport;
 	init_timer(&gf2k->timer);
 	gf2k->timer.data = (long) gf2k;
 	gf2k->timer.function = gf2k_timer;
 
+	gameport_set_drvdata(gameport, gf2k);
+
 	err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW);
 	if (err)
 		goto fail1;
@@ -345,16 +345,18 @@
 	return 0;
 
 fail2:	gameport_close(gameport);
-fail1:	kfree(gf2k);
+fail1:	gameport_set_drvdata(gameport, NULL);
+	kfree(gf2k);
 	return err;
 }
 
 static void gf2k_disconnect(struct gameport *gameport)
 {
-	struct gf2k *gf2k = gameport->private;
+	struct gf2k *gf2k = gameport_get_drvdata(gameport);
 
 	input_unregister_device(&gf2k->dev);
 	gameport_close(gameport);
+	gameport_set_drvdata(gameport, NULL);
 	kfree(gf2k);
 }
 
drivers/input/joystick/grip.c +6 -4
diff -Nru a/drivers/input/joystick/grip.c b/drivers/input/joystick/grip.c
@@ -310,13 +310,13 @@
 	if (!(grip = kcalloc(1, sizeof(struct grip), GFP_KERNEL)))
 		return -ENOMEM;
 
-	gameport->private = grip;
-
 	grip->gameport = gameport;
 	init_timer(&grip->timer);
 	grip->timer.data = (long) grip;
 	grip->timer.function = grip_timer;
 
+	gameport_set_drvdata(gameport, grip);
+
 	err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW);
 	if (err)
 		goto fail1;
@@ -386,19 +386,21 @@
 	return 0;
 
 fail2:	gameport_close(gameport);
-fail1:	kfree(grip);
+fail1:	gameport_set_drvdata(gameport, NULL);
+	kfree(grip);
 	return err;
 }
 
 static void grip_disconnect(struct gameport *gameport)
 {
-	struct grip *grip = gameport->private;
+	struct grip *grip = gameport_get_drvdata(gameport);
 	int i;
 
 	for (i = 0; i < 2; i++)
 		if (grip->mode[i])
 			input_unregister_device(grip->dev + i);
 	gameport_close(gameport);
+	gameport_set_drvdata(gameport, NULL);
 	kfree(grip);
 }
 
drivers/input/joystick/grip_mp.c +6 -3
diff -Nru a/drivers/input/joystick/grip_mp.c b/drivers/input/joystick/grip_mp.c
@@ -626,12 +626,13 @@
 	if (!(grip = kcalloc(1, sizeof(struct grip_mp), GFP_KERNEL)))
 		return -ENOMEM;
 
-	gameport->private = grip;
 	grip->gameport = gameport;
 	init_timer(&grip->timer);
 	grip->timer.data = (long) grip;
 	grip->timer.function = grip_timer;
 
+	gameport_set_drvdata(gameport, grip);
+
 	err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW);
 	if (err)
 		goto fail1;
@@ -650,19 +651,21 @@
 	return 0;
 
 fail2:	gameport_close(gameport);
-fail1:	kfree(grip);
+fail1:	gameport_set_drvdata(gameport, NULL);
+	kfree(grip);
 	return err;
 }
 
 static void grip_disconnect(struct gameport *gameport)
 {
+	struct grip_mp *grip = gameport_get_drvdata(gameport);
 	int i;
-	struct grip_mp *grip = gameport->private;
 
 	for (i = 0; i < 4; i++)
 		if (grip->registered[i])
 			input_unregister_device(grip->dev + i);
 	gameport_close(gameport);
+	gameport_set_drvdata(gameport, NULL);
 	kfree(grip);
 }
 
drivers/input/joystick/guillemot.c +5 -4
diff -Nru a/drivers/input/joystick/guillemot.c b/drivers/input/joystick/guillemot.c
@@ -193,13 +193,13 @@
 	if (!(guillemot = kcalloc(1, sizeof(struct guillemot), GFP_KERNEL)))
 		return -ENOMEM;
 
-	gameport->private = guillemot;
-
 	guillemot->gameport = gameport;
 	init_timer(&guillemot->timer);
 	guillemot->timer.data = (long) guillemot;
 	guillemot->timer.function = guillemot_timer;
 
+	gameport_set_drvdata(gameport, guillemot);
+
 	err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW);
 	if (err)
 		goto fail1;
@@ -257,13 +257,14 @@
 	return 0;
 
 fail2:	gameport_close(gameport);
-fail1:  kfree(guillemot);
+fail1:  gameport_set_drvdata(gameport, NULL);
+	kfree(guillemot);
 	return err;
 }
 
 static void guillemot_disconnect(struct gameport *gameport)
 {
-	struct guillemot *guillemot = gameport->private;
+	struct guillemot *guillemot = gameport_get_drvdata(gameport);
 
 	printk(KERN_INFO "guillemot.c: Failed %d reads out of %d on %s\n", guillemot->reads, guillemot->bads, guillemot->phys);
 	input_unregister_device(&guillemot->dev);
drivers/input/joystick/interact.c +6 -4
diff -Nru a/drivers/input/joystick/interact.c b/drivers/input/joystick/interact.c
@@ -223,13 +223,13 @@
 	if (!(interact = kcalloc(1, sizeof(struct interact), GFP_KERNEL)))
 		return -ENOMEM;
 
-	gameport->private = interact;
-
 	interact->gameport = gameport;
 	init_timer(&interact->timer);
 	interact->timer.data = (long) interact;
 	interact->timer.function = interact_timer;
 
+	gameport_set_drvdata(gameport, interact);
+
 	err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW);
 	if (err)
 		goto fail1;
@@ -291,16 +291,18 @@
 	return 0;
 
 fail2:	gameport_close(gameport);
-fail1:  kfree(interact);
+fail1:  gameport_set_drvdata(gameport, NULL);
+	kfree(interact);
 	return err;
 }
 
 static void interact_disconnect(struct gameport *gameport)
 {
-	struct interact *interact = gameport->private;
+	struct interact *interact = gameport_get_drvdata(gameport);
 
 	input_unregister_device(&interact->dev);
 	gameport_close(gameport);
+	gameport_set_drvdata(gameport, NULL);
 	kfree(interact);
 }
 
drivers/input/joystick/sidewinder.c +6 -4
diff -Nru a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
@@ -605,13 +605,13 @@
 		goto fail1;
 	}
 
-	gameport->private = sw;
-
 	sw->gameport = gameport;
 	init_timer(&sw->timer);
 	sw->timer.data = (long) sw;
 	sw->timer.function = sw_timer;
 
+	gameport_set_drvdata(gameport, sw);
+
 	err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW);
 	if (err)
 		goto fail1;
@@ -770,7 +770,8 @@
 	return 0;
 
 fail2:	gameport_close(gameport);
-fail1:	kfree(sw);
+fail1:	gameport_set_drvdata(gameport, NULL);
+	kfree(sw);
 	kfree(buf);
 	kfree(idbuf);
 	return err;
@@ -778,12 +779,13 @@
 
 static void sw_disconnect(struct gameport *gameport)
 {
+	struct sw *sw = gameport_get_drvdata(gameport);
 	int i;
 
-	struct sw *sw = gameport->private;
 	for (i = 0; i < sw->number; i++)
 		input_unregister_device(sw->dev + i);
 	gameport_close(gameport);
+	gameport_set_drvdata(gameport, NULL);
 	kfree(sw);
 }
 
drivers/input/joystick/tmdc.c +6 -4
diff -Nru a/drivers/input/joystick/tmdc.c b/drivers/input/joystick/tmdc.c
@@ -270,13 +270,13 @@
 	if (!(tmdc = kcalloc(1, sizeof(struct tmdc), GFP_KERNEL)))
 		return -ENOMEM;
 
-	gameport->private = tmdc;
-
 	tmdc->gameport = gameport;
 	init_timer(&tmdc->timer);
 	tmdc->timer.data = (long) tmdc;
 	tmdc->timer.function = tmdc_timer;
 
+	gameport_set_drvdata(gameport, tmdc);
+
 	err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW);
 	if (err)
 		goto fail1;
@@ -347,19 +347,21 @@
 	return 0;
 
 fail2:	gameport_close(gameport);
-fail1:	kfree(tmdc);
+fail1:	gameport_set_drvdata(gameport, NULL);
+	kfree(tmdc);
 	return err;
 }
 
 static void tmdc_disconnect(struct gameport *gameport)
 {
-	struct tmdc *tmdc = gameport->private;
+	struct tmdc *tmdc = gameport_get_drvdata(gameport);
 	int i;
 
 	for (i = 0; i < 2; i++)
 		if (tmdc->exists & (1 << i))
 			input_unregister_device(tmdc->dev + i);
 	gameport_close(gameport);
+	gameport_set_drvdata(gameport, NULL);
 	kfree(tmdc);
 }
 
include/linux/gameport.h +14 -1
diff -Nru a/include/linux/gameport.h b/include/linux/gameport.h
@@ -15,7 +15,6 @@
 
 struct gameport {
 
-	void *private;		/* Private pointer for joystick drivers */
 	void *port_data;	/* Private pointer for gameport drivers */
 	char name[32];
 	char phys[32];
@@ -89,6 +88,20 @@
 
 void gameport_set_phys(struct gameport *gameport, const char *fmt, ...)
 	__attribute__ ((format (printf, 2, 3)));
+
+/*
+ * Use the following fucntions to manipulate gameport's per-port
+ * driver-specific data.
+ */
+static inline void *gameport_get_drvdata(struct gameport *gameport)
+{
+	return dev_get_drvdata(&gameport->dev);
+}
+
+static inline void gameport_set_drvdata(struct gameport *gameport, void *data)
+{
+	dev_set_drvdata(&gameport->dev, data);
+}
 
 /*
  * Use the following fucntions to pin gameport's driver in process context

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click

#11 lore raw
In reply to Dmitry Torokhov
Quoted 4 lines · Dmitry Torokhov

This series of patches adds a new "gameport" bus to the driver model. It is implemented very similarly to "serio" bus and also allows individual drivers to be manually bound/disconnected from a port by manipulating port's "drvctl" attribute.

Good work! I'm pulling it into my tree. And test.

Quoted 8 lines

The changes can also be pulled from my tree (which has Vojtech's input tree as a parent):

bk pull bk://dtor.bkbits.net/input

I am CC-ing ALSA list as the changes touch quite a few sound drivers.

Comments/testing is appreciated.

Signature · 9 lines
Vojtech Pavlik
SuSE Labs, SuSE CR


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
#12 lore raw
In reply to Dmitry Torokhov
Quoted 4 lines · Dmitry Torokhov

This series of patches adds a new "gameport" bus to the driver model. It is implemented very similarly to "serio" bus and also allows individual drivers to be manually bound/disconnected from a port by manipulating port's "drvctl" attribute.

Good work! I'm pulling it into my tree. And test.

Quoted 8 lines

The changes can also be pulled from my tree (which has Vojtech's input tree as a parent):

bk pull bk://dtor.bkbits.net/input

I am CC-ing ALSA list as the changes touch quite a few sound drivers.

Comments/testing is appreciated.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR