public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dtor_core@ameritech.net>
To: InputML <linux-input@atrey.karlin.mff.cuni.cz>
Cc: alsa-devel@alsa-project.org, LKML <linux-kernel@vger.kernel.org>,
	Vojtech Pavlik <vojtech@suse.cz>
Subject: [PATCH 4/10] Gameport: prepare to dynamic allocation
Date: Fri, 11 Feb 2005 02:01:30 -0500	[thread overview]
Message-ID: <200502110201.31239.dtor_core@ameritech.net> (raw)
In-Reply-To: <200502110201.00916.dtor_core@ameritech.net>


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


ChangeSet@1.2152, 2005-02-11 01:18:48-05:00, dtor_core@ameritech.net
  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.
  
  Signed-off-by: Dmitry Torokhov <dtor@mail.ru>


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


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



diff -Nru a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
--- a/drivers/input/gameport/gameport.c	2005-02-11 01:36:13 -05:00
+++ b/drivers/input/gameport/gameport.c	2005-02-11 01:36:13 -05:00
@@ -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)
diff -Nru a/include/linux/gameport.h b/include/linux/gameport.h
--- a/include/linux/gameport.h	2005-02-11 01:36:13 -05:00
+++ b/include/linux/gameport.h	2005-02-11 01:36:13 -05:00
@@ -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);

  reply	other threads:[~2005-02-11  7:09 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-11  6:58 [PATCH 0/10] Convert gameport to driver model/sysfs Dmitry Torokhov
2005-02-11  6:59 ` [PATCH 1/10] Gameport: rename driver to port_data Dmitry Torokhov
2005-02-11  7:00   ` [PATCH 2/10] Gameport: rename gameport_dev to gameport_driver Dmitry Torokhov
2005-02-11  7:00     ` [PATCH 3/10] Gameport: connect() is mandatory Dmitry Torokhov
2005-02-11  7:01       ` Dmitry Torokhov [this message]
2005-02-11  7:02         ` [PATCH 5/10] Gameport: convert input/gameport to dynamic allocation Dmitry Torokhov
2005-02-11  7:02           ` [PATCH 6/10] Gameport: convert sound/oss " Dmitry Torokhov
2005-02-11  7:03             ` [PATCH 7/10] Gameport: convert sound/alsa " Dmitry Torokhov
2005-02-11  7:04               ` [PATCH 8/10] Gameport: add "gameport" sysfs bus, add drivers Dmitry Torokhov
2005-02-11  7:04                 ` [PATCH 9/10] Gameport: complete sysfs integration Dmitry Torokhov
2005-02-11  7:05                   ` [PATCH 10/10] Gameport: replace ->private with gameport_get/set_drvdata Dmitry Torokhov
2005-02-11  8:11 ` [PATCH 0/10] Convert gameport to driver model/sysfs Vojtech Pavlik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200502110201.31239.dtor_core@ameritech.net \
    --to=dtor_core@ameritech.net \
    --cc=alsa-devel@alsa-project.org \
    --cc=linux-input@atrey.karlin.mff.cuni.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vojtech@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox