All of lore.kernel.org
 help / color / mirror / Atom feed
From: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-acpi@vger.kernel.org,
	Johannes Berg <johannes@sipsolutions.net>,
	Len Brown <lenb@kernel.org>,
	Alan Jenkins <alan-jenkins@tuffmail.co.uk>,
	ibm-acpi-devel@lists.sourceforge.net
Subject: Re: [ibm-acpi-devel] [PATCH 10/10] thinkpad-acpi: sync input device EV_SW state directly
Date: Wed, 9 Dec 2009 18:32:01 -0200	[thread overview]
Message-ID: <20091209203201.GC29575@khazad-dum.debian.net> (raw)
In-Reply-To: <20091209172119.GB4456@core.coreip.homeip.net>

On Wed, 09 Dec 2009, Dmitry Torokhov wrote:
> > input_report_switch() will call input_event(), which will have a 50% chance
> > of doing the wrong thing at startup (i.e. issue an event) since it will look
> > at the state of the sw bitmap to decide whether to issue an event or not.
> > 
> 
> It will not propagate events because until you register the device there
> won't be any consumers attached to it. So the only thing that will
> happen is that it will sync internal state of the device from input core
> point of view with the true state of the hardware.

Ah, I see.  Cute trick, and yes, that would work just fine.  I will do that,
it certainly beats accessing the sw bitmap directly.

Is it documented anywhere?

Still, please look at the patch below...  Would something like this be a
cleaner API?  It is certainly more obvious, and it is cleaner on the driver
side (one function call does everything, instead of a call to
input_set_capability plus a call to whatever the driver needs to issue the
initial EV_SW event)...

I left the thinkpad-acpi hunk in it to show how it makes things easier for
the driver.

Author: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
Date:   Sun Dec 6 14:04:30 2009 -0200

    input: add API to set initial EV_SW state
    
    Add an API for input drivers to init EV_SW switches.
    
    Change the thinkpad-acpi driver to use the new API.
    
    Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
    Cc: Dmitry Torokhov <dtor@mail.ru>

diff --git a/drivers/input/input.c b/drivers/input/input.c
index 7c237e6..4fcb362 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -1388,6 +1388,33 @@ void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int
 EXPORT_SYMBOL(input_set_capability);
 
 /**
+ * input_init_switch - prepare device to handle a certain EV_SW event
+ * @dev: device that is capable of issuing the EV_SW event
+ * @code: event code
+ * @state: initial state for the switch
+ *
+ * This function sets the corresponding bits in the capability bitmap,
+ * switch capability bitmap, and switch state bitmap.
+ */
+void input_init_switch(struct input_dev *dev, unsigned int code, bool state)
+{
+	if (code > SW_MAX) {
+		printk(KERN_ERR
+			"input_init_switch: unknown code %u\n",
+			code);
+		dump_stack();
+		return;
+	}
+
+	input_set_capability(dev, EV_SW, code);
+	if (state)
+		__set_bit(code, dev->sw);
+	else
+		__clear_bit(code, dev->sw);
+}
+EXPORT_SYMBOL(input_init_switch);
+
+/**
  * input_register_device - register device with input core
  * @dev: device to be registered
  *
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index a63ceb1..efa6830 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -3365,16 +3365,12 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
 		}
 	}
 
-	if (tp_features.hotkey_wlsw) {
-		input_set_capability(tpacpi_inputdev, EV_SW, SW_RFKILL_ALL);
-		if (radiosw_state)
-			__set_bit(SW_RFKILL_ALL, tpacpi_inputdev->sw);
-	}
-	if (tp_features.hotkey_tablet) {
-		input_set_capability(tpacpi_inputdev, EV_SW, SW_TABLET_MODE);
-		if (tabletsw_state)
-			__set_bit(SW_TABLET_MODE, tpacpi_inputdev->sw);
-	}
+	if (tp_features.hotkey_wlsw)
+		input_init_switch(tpacpi_inputdev,
+				  SW_RFKILL_ALL, radiosw_state);
+	if (tp_features.hotkey_tablet)
+		input_init_switch(tpacpi_inputdev,
+				  SW_TABLET_MODE, tabletsw_state);
 
 	/* Do not issue duplicate brightness change events to
 	 * userspace */
diff --git a/include/linux/input.h b/include/linux/input.h
index 8b3bc3e..40ecd48 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -1353,6 +1353,8 @@ static inline void input_set_abs_params(struct input_dev *dev, int axis, int min
 int input_get_keycode(struct input_dev *dev, int scancode, int *keycode);
 int input_set_keycode(struct input_dev *dev, int scancode, int keycode);
 
+void input_init_switch(struct input_dev *dev, unsigned int code, bool state);
+
 extern struct class input_class;
 
 /**


-- 
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh

  reply	other threads:[~2009-12-09 20:31 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-09  1:36 [GIT PATCH v2] thinkpad-acpi first set of changes for 2.6.33 (v2) Henrique de Moraes Holschuh
2009-12-09  1:36 ` [PATCH 01/10] thinkpad-acpi: fix default brightness_mode for R50e/R51 Henrique de Moraes Holschuh
2009-12-09  1:36 ` [PATCH 02/10] thinkpad-acpi: preserve rfkill state across suspend/resume Henrique de Moraes Holschuh
2009-12-09  1:36 ` [PATCH 03/10] thinkpad-acpi: fix some version quirks Henrique de Moraes Holschuh
2009-12-09  1:36 ` [PATCH 04/10] thinkpad-acpi: issue backlight class events Henrique de Moraes Holschuh
2009-12-09  1:36 ` [PATCH 05/10] thinkpad-acpi: silence bogus complain during rmmod Henrique de Moraes Holschuh
2009-12-09  1:36 ` [PATCH 06/10] thinkpad-acpi: adopt input device Henrique de Moraes Holschuh
2009-12-09  1:36 ` [PATCH 07/10] thinkpad-acpi: expose module parameters Henrique de Moraes Holschuh
2009-12-09  1:36 ` [PATCH 08/10] thinkpad-acpi: log temperatures on termal alarm (v2) Henrique de Moraes Holschuh
2009-12-09 10:46   ` Pavel Machek
2009-12-09  1:36 ` [PATCH 09/10] thinkpad-acpi: use input_set_capability Henrique de Moraes Holschuh
2009-12-09  1:36 ` [PATCH 10/10] thinkpad-acpi: sync input device EV_SW state directly Henrique de Moraes Holschuh
     [not found]   ` <1260322590-5571-11-git-send-email-hmh-N3TV7GIv+o9fyO9Q7EP/yw@public.gmane.org>
2009-12-09  1:45     ` Dmitry Torokhov
2009-12-09 16:30       ` [ibm-acpi-devel] " Henrique de Moraes Holschuh
     [not found]         ` <20091209163041.GA29575-ZGHd14iZgfaRjzvQDGKj+xxZW9W5cXbT@public.gmane.org>
2009-12-09 17:21           ` Dmitry Torokhov
2009-12-09 20:32             ` Henrique de Moraes Holschuh [this message]
2009-12-09 20:59               ` [ibm-acpi-devel] " Dmitry Torokhov
2009-12-10 13:19                 ` Henrique de Moraes Holschuh
2009-12-10 18:59                   ` Dmitry Torokhov
     [not found]                     ` <20091210185922.GD23717-WlK9ik9hQGAhIp7JRqBPierSzoNAToWh@public.gmane.org>
2009-12-11  0:46                       ` Henrique de Moraes Holschuh
     [not found]                         ` <20091211004602.GB24245-ZGHd14iZgfaRjzvQDGKj+xxZW9W5cXbT@public.gmane.org>
2009-12-11  7:54                           ` Dmitry Torokhov
2009-12-11 15:02                             ` [ibm-acpi-devel] " Henrique de Moraes Holschuh
2009-12-09 20:47 ` [GIT PATCH v2] thinkpad-acpi first set of changes for 2.6.33 (v2) Len Brown
2009-12-09 22:32   ` Henrique de Moraes Holschuh

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=20091209203201.GC29575@khazad-dum.debian.net \
    --to=hmh@hmh.eng.br \
    --cc=alan-jenkins@tuffmail.co.uk \
    --cc=dmitry.torokhov@gmail.com \
    --cc=ibm-acpi-devel@lists.sourceforge.net \
    --cc=johannes@sipsolutions.net \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.