All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dell-laptop: support synaptics touchpad led
@ 2011-06-01  8:34 AceLan Kao
  2011-06-01 13:31 ` Matthew Garrett
  0 siblings, 1 reply; 6+ messages in thread
From: AceLan Kao @ 2011-06-01  8:34 UTC (permalink / raw)
  To: platform-driver-x86, Matthew Garrett

The TP-LOCK-LED would bright while TP-disablement.
You can implement 97 command services routing of P/S2 device.
Code like below:
out 0x64,0x97 ;set 0x97 to command port;0x64 is command port
out 0x60,0x01 ;set 0x01 to data port then make LED bright;0x60 is data port
out 0x60,0x02 ;set 0x02 to data port then make LED dark

Before you send the action to the port, you must make sure the Input buffer
is empty (port 0x64).

Signed-off-by: AceLan Kao <acelan.kao@canonical.com>
---
 drivers/platform/x86/dell-laptop.c |  105 +++++++++++++++++++++++++++++++++---
 1 files changed, 98 insertions(+), 7 deletions(-)

diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c
index d3841de..65efa74 100644
--- a/drivers/platform/x86/dell-laptop.c
+++ b/drivers/platform/x86/dell-laptop.c
@@ -65,19 +65,14 @@ static int da_command_code;
 static int da_num_tokens;
 static struct calling_interface_token *da_tokens;
 
-static struct platform_driver platform_driver = {
-	.driver = {
-		.name = "dell-laptop",
-		.owner = THIS_MODULE,
-	}
-};
-
 static struct platform_device *platform_device;
 static struct backlight_device *dell_backlight_device;
 static struct rfkill *wifi_rfkill;
 static struct rfkill *bluetooth_rfkill;
 static struct rfkill *wwan_rfkill;
 
+static struct delayed_work dell_touchpadled_update_work;
+static int touchpad_led_status;
 static const struct dmi_system_id __initdata dell_device_table[] = {
 	{
 		.ident = "Dell laptop",
@@ -572,6 +567,45 @@ static const struct backlight_ops dell_ops = {
 	.update_status  = dell_send_intensity,
 };
 
+static void dell_touchpadled_on(void)
+{
+	while (inb(0x64) & 0x02)
+		udelay(100);
+	outb(0x97 , 0x64);
+
+	while (inb(0x64) & 0x02)
+		udelay(100);
+	outb(1, 0x60);
+
+	touchpad_led_status = 1;
+}
+
+static void dell_touchpadled_off(void)
+{
+	while (inb(0x64) & 0x02)
+		udelay(100);
+	outb(0x97 , 0x64);
+
+	while (inb(0x64) & 0x02)
+		udelay(100);
+	outb(2, 0x60);
+
+	touchpad_led_status = 0;
+}
+
+/*
+ * Called for each KEY_F22 key press event.
+ */
+static void dell_touchpadled_update(struct work_struct *work)
+{
+	touchpad_led_status = 1 - touchpad_led_status;
+
+	if (touchpad_led_status == 1)
+		dell_touchpadled_on();
+	else
+		dell_touchpadled_off();
+}
+
 static bool dell_laptop_i8042_filter(unsigned char data, unsigned char str,
 			      struct serio *port)
 {
@@ -589,6 +623,10 @@ static bool dell_laptop_i8042_filter(unsigned char data, unsigned char str,
 			schedule_delayed_work(&dell_rfkill_work,
 					      round_jiffies_relative(HZ));
 			break;
+		case 0x1E:	/* F22 */
+			schedule_delayed_work(&dell_touchpadled_update_work,
+					      0);
+			break;
 		}
 		extended = false;
 	}
@@ -596,11 +634,64 @@ static bool dell_laptop_i8042_filter(unsigned char data, unsigned char str,
 	return false;
 }
 
+static void restore_touchpad_led(void)
+{
+	/*
+	 * We don't want to change the value of touchpad_led_status while
+	 * resuming, so we modify the value here and it'll be changed back
+	 * in the work queue
+	 */
+	touchpad_led_status = 1 - touchpad_led_status;
+	/* The delay is needed to wait the chip wake up */
+	schedule_delayed_work(&dell_touchpadled_update_work, 1000);
+}
+
+static int __devinit dell_laptop_probe(struct platform_device *device)
+{
+	INIT_DELAYED_WORK(&dell_touchpadled_update_work,
+			  dell_touchpadled_update);
+	return 0;
+}
+
+static int dell_laptop_remove(struct platform_device *device)
+{
+	return 0;
+}
+
+static int dell_laptop_suspend(struct device *dev)
+{
+	return 0;
+}
+
+static int dell_laptop_resume(struct device *dev)
+{
+	restore_touchpad_led();
+	return 0;
+}
+
+static const struct dev_pm_ops dell_laptop_pm_ops = {
+	.suspend = dell_laptop_suspend,
+	.resume  = dell_laptop_resume,
+	.restore = dell_laptop_resume,
+};
+
+static struct platform_driver platform_driver = {
+	.driver = {
+		.name = "dell-laptop",
+		.owner = THIS_MODULE,
+		.pm    = &dell_laptop_pm_ops,
+	},
+	.probe  = dell_laptop_probe,
+	.remove = dell_laptop_remove,
+};
+
 static int __init dell_init(void)
 {
 	int max_intensity = 0;
 	int ret;
 
+	touchpad_led_status = 0;
+
 	if (!dmi_check_system(dell_device_table))
 		return -ENODEV;
 
-- 
1.7.4.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] dell-laptop: support synaptics touchpad led
  2011-06-01  8:34 [PATCH] dell-laptop: support synaptics touchpad led AceLan Kao
@ 2011-06-01 13:31 ` Matthew Garrett
  2011-06-02  1:30   ` AceLan Kao
  0 siblings, 1 reply; 6+ messages in thread
From: Matthew Garrett @ 2011-06-01 13:31 UTC (permalink / raw)
  To: AceLan Kao; +Cc: platform-driver-x86

On Wed, Jun 01, 2011 at 04:34:48PM +0800, AceLan Kao wrote:
> The TP-LOCK-LED would bright while TP-disablement.
> You can implement 97 command services routing of P/S2 device.
> Code like below:
> out 0x64,0x97 ;set 0x97 to command port;0x64 is command port
> out 0x60,0x01 ;set 0x01 to data port then make LED bright;0x60 is data port
> out 0x60,0x02 ;set 0x02 to data port then make LED dark
> 
> Before you send the action to the port, you must make sure the Input buffer
> is empty (port 0x64).

NAK - you're sending commands to the touchpad. The code for that needs 
to live in the touchpad driver, not dell-laptop (what happens if these 
commands are sent to different types of touchpad?). The scancode needs 
to be mapped to an appropriate keycode and userspace needs to tie them 
together.

-- 
Matthew Garrett | mjg59@srcf.ucam.org

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] dell-laptop: support synaptics touchpad led
  2011-06-01 13:31 ` Matthew Garrett
@ 2011-06-02  1:30   ` AceLan Kao
  2011-06-02  2:05     ` Chris Bagwell
  2011-06-02  2:23     ` Matthew Garrett
  0 siblings, 2 replies; 6+ messages in thread
From: AceLan Kao @ 2011-06-02  1:30 UTC (permalink / raw)
  To: Matthew Garrett; +Cc: platform-driver-x86

Mattew,

Dell tells us that they will use the same touchpad chip for their products,
with the same touchpad LED layout, so I place the code in the dell-laptop.
And F22 already map to enable/disable touchpad in X, BIOS and synaptics driver
do nothing for this event, and my code only turns on/off the touchpad LED,
not enable/disable the touchpad.

BIOS should manage this kind of action to enable/disable touchpad and the LED,
but Dell doesn't want to modify their BIOS to do that, since the
touchpad driver of
MS Windows manages to enable/disable touchpad and the LED by themselves,
so Linux should do the same thing as Windows does.

That's why we need those code and why I think dell-laptop is a good
place for them.

Best regards,
AceLan Kao.

2011/6/1 Matthew Garrett <mjg59@srcf.ucam.org>:
> On Wed, Jun 01, 2011 at 04:34:48PM +0800, AceLan Kao wrote:
>> The TP-LOCK-LED would bright while TP-disablement.
>> You can implement 97 command services routing of P/S2 device.
>> Code like below:
>> out 0x64,0x97 ;set 0x97 to command port;0x64 is command port
>> out 0x60,0x01 ;set 0x01 to data port then make LED bright;0x60 is data port
>> out 0x60,0x02 ;set 0x02 to data port then make LED dark
>>
>> Before you send the action to the port, you must make sure the Input buffer
>> is empty (port 0x64).
>
> NAK - you're sending commands to the touchpad. The code for that needs
> to live in the touchpad driver, not dell-laptop (what happens if these
> commands are sent to different types of touchpad?). The scancode needs
> to be mapped to an appropriate keycode and userspace needs to tie them
> together.
>
> --
> Matthew Garrett | mjg59@srcf.ucam.org
>



-- 
Chia-Lin Kao(AceLan)
http://blog.acelan.idv.tw/
E-Mail: acelan.kaoATcanonical.com (s/AT/@/)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] dell-laptop: support synaptics touchpad led
  2011-06-02  1:30   ` AceLan Kao
@ 2011-06-02  2:05     ` Chris Bagwell
  2011-06-02  3:18       ` AceLan Kao
  2011-06-02  2:23     ` Matthew Garrett
  1 sibling, 1 reply; 6+ messages in thread
From: Chris Bagwell @ 2011-06-02  2:05 UTC (permalink / raw)
  To: AceLan Kao; +Cc: Matthew Garrett, platform-driver-x86

On Wed, Jun 1, 2011 at 8:30 PM, AceLan Kao <acelan.kao@canonical.com> wrote:
> Mattew,
>
> Dell tells us that they will use the same touchpad chip for their products,
> with the same touchpad LED layout, so I place the code in the dell-laptop.
> And F22 already map to enable/disable touchpad in X, BIOS and synaptics driver
> do nothing for this event, and my code only turns on/off the touchpad LED,
> not enable/disable the touchpad.

X has recently (last year or less) cleaned these key definitions up a
little.  F21 is defined to toggle touchpad on/off and F22 forces
touchpad ON and F23 forces touchpad OFF (XF86TouchpadToggle,
XF86TouchpadOn, and XF86TouchpadOff respectively).

The 2.x version of Gnome released right before 3.0 understood this
mapping.  I'm trying to track down why Gnome 3 doesn't treat F21 as
toggle though.

>
> BIOS should manage this kind of action to enable/disable touchpad and the LED,
> but Dell doesn't want to modify their BIOS to do that, since the
> touchpad driver of
> MS Windows manages to enable/disable touchpad and the LED by themselves,
> so Linux should do the same thing as Windows does.
>
> That's why we need those code and why I think dell-laptop is a good
> place for them.

If you can send F22/F23 to match LED and using matching X then I think
you can get window's behaviour.

Sorry, I don't have ready access to version of dell-laptop where it
understands KEY_F22 to see how easy it is to make that change.

Chris

>
> Best regards,
> AceLan Kao.
>
> 2011/6/1 Matthew Garrett <mjg59@srcf.ucam.org>:
>> On Wed, Jun 01, 2011 at 04:34:48PM +0800, AceLan Kao wrote:
>>> The TP-LOCK-LED would bright while TP-disablement.
>>> You can implement 97 command services routing of P/S2 device.
>>> Code like below:
>>> out 0x64,0x97 ;set 0x97 to command port;0x64 is command port
>>> out 0x60,0x01 ;set 0x01 to data port then make LED bright;0x60 is data port
>>> out 0x60,0x02 ;set 0x02 to data port then make LED dark
>>>
>>> Before you send the action to the port, you must make sure the Input buffer
>>> is empty (port 0x64).
>>
>> NAK - you're sending commands to the touchpad. The code for that needs
>> to live in the touchpad driver, not dell-laptop (what happens if these
>> commands are sent to different types of touchpad?). The scancode needs
>> to be mapped to an appropriate keycode and userspace needs to tie them
>> together.
>>
>> --
>> Matthew Garrett | mjg59@srcf.ucam.org
>>
>
>
>
> --
> Chia-Lin Kao(AceLan)
> http://blog.acelan.idv.tw/
> E-Mail: acelan.kaoATcanonical.com (s/AT/@/)
> --
> To unsubscribe from this list: send the line "unsubscribe platform-driver-x86" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] dell-laptop: support synaptics touchpad led
  2011-06-02  1:30   ` AceLan Kao
  2011-06-02  2:05     ` Chris Bagwell
@ 2011-06-02  2:23     ` Matthew Garrett
  1 sibling, 0 replies; 6+ messages in thread
From: Matthew Garrett @ 2011-06-02  2:23 UTC (permalink / raw)
  To: AceLan Kao; +Cc: platform-driver-x86

On Thu, Jun 02, 2011 at 09:30:56AM +0800, AceLan Kao wrote:
> Mattew,
> 
> Dell tells us that they will use the same touchpad chip for their products,
> with the same touchpad LED layout, so I place the code in the dell-laptop.

Forever? I don't believe it's possible for Dell to guarantee that. The 
command sequenece is sent to the touchpad, so it needs to go in the 
touchpad driver.

> And F22 already map to enable/disable touchpad in X, BIOS and synaptics driver
> do nothing for this event, and my code only turns on/off the touchpad LED,
> not enable/disable the touchpad.

If this were to be done in kernel then it should be via a notifier chain 
to the touchpad driver, but I suspect that you'd still get pushback on 
that. It's better to leave this kind of thing to userland.

> BIOS should manage this kind of action to enable/disable touchpad and 
> the LED, but Dell doesn't want to modify their BIOS to do that, since 
> the touchpad driver of MS Windows manages to enable/disable touchpad 
> and the LED by themselves, so Linux should do the same thing as 
> Windows does.
>
> That's why we need those code and why I think dell-laptop is a good
> place for them.

I'm afraid not. dell-laptop only contains code that speaks to 
dell-specific hardware. It seems likely that this command sequence 
performs LED control via the touchpad rather than via any dell-specific 
mechanism, so the code needs to go in the touchpad driver.

-- 
Matthew Garrett | mjg59@srcf.ucam.org

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] dell-laptop: support synaptics touchpad led
  2011-06-02  2:05     ` Chris Bagwell
@ 2011-06-02  3:18       ` AceLan Kao
  0 siblings, 0 replies; 6+ messages in thread
From: AceLan Kao @ 2011-06-02  3:18 UTC (permalink / raw)
  To: Chris Bagwell; +Cc: Matthew Garrett, platform-driver-x86

Matthew,

We had two project with different touchpad chips, and confirmed with
ODM that the low level implementation are same.
So, the code could work on Synaptics and ALPS chip.

2011/6/2 Chris Bagwell <chris@cnpbagwell.com>:
> On Wed, Jun 1, 2011 at 8:30 PM, AceLan Kao <acelan.kao@canonical.com> wrote:
>> Mattew,
>>
>> Dell tells us that they will use the same touchpad chip for their products,
>> with the same touchpad LED layout, so I place the code in the dell-laptop.
>> And F22 already map to enable/disable touchpad in X, BIOS and synaptics driver
>> do nothing for this event, and my code only turns on/off the touchpad LED,
>> not enable/disable the touchpad.
>
> X has recently (last year or less) cleaned these key definitions up a
> little.  F21 is defined to toggle touchpad on/off and F22 forces
> touchpad ON and F23 forces touchpad OFF (XF86TouchpadToggle,
> XF86TouchpadOn, and XF86TouchpadOff respectively).
>
> The 2.x version of Gnome released right before 3.0 understood this
> mapping.  I'm trying to track down why Gnome 3 doesn't treat F21 as
> toggle though.

Yes, I noticed that F21~F23 keys changed, but F22 works for my
environment(Ubuntu Natty) now.
I'll test it again on Ubuntu Oneiric to see if the new keys take
actions of the function, then I'll do the modification.

>
>>
>> BIOS should manage this kind of action to enable/disable touchpad and the LED,
>> but Dell doesn't want to modify their BIOS to do that, since the
>> touchpad driver of
>> MS Windows manages to enable/disable touchpad and the LED by themselves,
>> so Linux should do the same thing as Windows does.
>>
>> That's why we need those code and why I think dell-laptop is a good
>> place for them.
>
> If you can send F22/F23 to match LED and using matching X then I think
> you can get window's behaviour.
>
> Sorry, I don't have ready access to version of dell-laptop where it
> understands KEY_F22 to see how easy it is to make that change.


Best regards,
AceLan Kao.

-- 
Chia-Lin Kao(AceLan)
http://blog.acelan.idv.tw/
E-Mail: acelan.kaoATcanonical.com (s/AT/@/)

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-06-02  3:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-01  8:34 [PATCH] dell-laptop: support synaptics touchpad led AceLan Kao
2011-06-01 13:31 ` Matthew Garrett
2011-06-02  1:30   ` AceLan Kao
2011-06-02  2:05     ` Chris Bagwell
2011-06-02  3:18       ` AceLan Kao
2011-06-02  2:23     ` Matthew Garrett

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.