Skip to contentSkip to conversation

input: keyboard: introduce lm8323 driver

PATCH In review Felipe Balbi 3 participants 5 messages Feb 19, 2009 – Feb 20, 2009 Input drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 input: keyboard: introduce lm8323 driver

From: Felipe Balbi <[email protected]>

lm8323 is the keypad driver used in n810 device. This driver has been sitting in linux-omap for quite a long time, it's about time to get comments from upstream and get it merged.

---
 drivers/input/keyboard/Kconfig  |    7 +
 drivers/input/keyboard/Makefile |    1 +
 drivers/input/keyboard/lm8323.c |  913 +++++++++++++++++++++++++++++++++++++++
 include/linux/i2c/lm8323.h      |   35 ++
 4 files changed, 956 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/keyboard/lm8323.c
 create mode 100644 include/linux/i2c/lm8323.h
drivers/input/keyboard/Kconfig +7 -0
index 3556168..2da936b 100644
@@ -259,6 +259,13 @@ config KEYBOARD_OMAP
 	  To compile this driver as a module, choose M here: the
 	  module will be called omap-keypad.
 
+config KEYBOARD_LM8323
+	tristate "LM8323 keypad chip"
+	depends on I2C
+	help
+	  If you say yes here you get support for the National Semiconductor
+	  LM8323 keypad controller.
+
 config KEYBOARD_PXA27x
 	tristate "PXA27x/PXA3xx keypad support"
 	depends on PXA27x || PXA3xx
drivers/input/keyboard/Makefile +1 -0
index 36351e1..f8bf562 100644
@@ -19,6 +19,7 @@ obj-$(CONFIG_KEYBOARD_TOSA)		+= tosakbd.o
 obj-$(CONFIG_KEYBOARD_HIL)		+= hil_kbd.o
 obj-$(CONFIG_KEYBOARD_HIL_OLD)		+= hilkbd.o
 obj-$(CONFIG_KEYBOARD_OMAP)		+= omap-keypad.o
+obj-$(CONFIG_KEYBOARD_LM8323)		+= lm8323.o
 obj-$(CONFIG_KEYBOARD_PXA27x)		+= pxa27x_keypad.o
 obj-$(CONFIG_KEYBOARD_PXA930_ROTARY)	+= pxa930_rotary.o
 obj-$(CONFIG_KEYBOARD_AAED2000)		+= aaed2000_kbd.o
drivers/input/keyboard/lm8323.c new file +913 -0

913 lines not on this page · raw message

include/linux/i2c/lm8323.h new file +35 -0
new file mode 100644
index 0000000..5eae5cc
@@ -0,0 +1,35 @@
+/*
+ * include/lm8323.h
+ *
+ * Configuration for LM8323 keypad driver.
+ */
+
+#ifndef __LINUX_LM8323_H
+#define __LINUX_LM8323_H
+
+#include <linux/types.h>
+
+/*
+ * Largest keycode that the chip can send, plus one,
+ * so keys can be mapped directly at the index of the
+ * LM8323 keycode instead of subtracting one.
+ */
+#define LM8323_KEYMAP_SIZE (0x7f + 1)
+
+struct lm8323_platform_data {
+	int debounce_time; /* Time to watch for key bouncing, in ms. */
+	int active_time; /* Idle time until sleep, in ms. */
+
+	int size_x;
+	int size_y;
+	int repeat : 1;
+	const s16 *keymap;
+
+	char *pwm1_name; /* Device name for PWM1. */
+	char *pwm2_name; /* Device name for PWM2. */
+	char *pwm3_name; /* Device name for PWM3. */
+
+	char *name; /* Device name. */
+};
+
+#endif /* __LINUX_LM8323_H */
Signature · 1 line
1.6.1.3
#1 lore raw

Hi Flipe,

drivers/input/keyboard/lm8323.c line 4

Quoted 10 lines
drivers/input/keyboard/lm8323.c new file +4 -0
new file mode 100644
index 0000000..27da93c
@@ -0,0 +1,913 @@
+/*
+ * drivers/i2c/chips/lm8323.c
+ *
+ * Copyright (C) 2007 Nokia Corporation

You might want to update this if you have updated some code before submitting to kernel list.

drivers/input/keyboard/lm8323.c line 750

Quoted 4 lines
drivers/input/keyboard/lm8323.c new file +4 -0
+
+       err = request_irq(client->irq, lm8323_irq,
+                         IRQF_TRIGGER_FALLING | IRQF_DISABLED |
+                         IRQF_SAMPLE_RANDOM, "lm8323", lm);

No need to add IRQF_SAMPLE_RANDOM, it is done input subsystem. Please check input_report_event.

drivers/input/keyboard/lm8323.c line 10

Quoted 2 lines
drivers/input/keyboard/lm8323.c new file +2 -0
+
+       set_irq_wake(client->irq, 1);

Shall we move to device_init_wakup + enable_irq_wake friends ?

Quoted 14 lines
drivers/input/keyboard/lm8323.c new file +14 -0
+
+       lm->kp_enabled = 1;
+       err = device_create_file(&client->dev, &dev_attr_disable_kp);
+       if (err < 0)
+               goto fail7;
+
+       idev = input_allocate_device();
+       if (!idev) {
+               err = -ENOMEM;
+               goto fail8;
+       }
+
+       if (pdata->name)
+               idev->name = pdata->name;

drivers/input/keyboard/lm8323.c line 780

Quoted 10 lines
drivers/input/keyboard/lm8323.c new file +10 -0
+       else
+               idev->name = "LM8323 keypad";
+       snprintf(lm->phys, sizeof(lm->phys), "%s/input-kp", client->dev.bus_id);
+       idev->phys = lm->phys;
+
+       lm->keys_down = 0;
+       idev->evbit[0] = BIT(EV_KEY);
+       for (i = 0; i < LM8323_KEYMAP_SIZE; i++) {
+               if (pdata->keymap[i] > 0)
+                       set_bit(pdata->keymap[i], idev->keybit);

No difference but better to use __set_bit, as atomicity is not required here.

drivers/input/keyboard/lm8323.c line 786

Quoted 6 lines
drivers/input/keyboard/lm8323.c new file +6 -0
+
+               lm->keymap[i] = pdata->keymap[i];
+       }
+
+       if (pdata->repeat)
+               set_bit(EV_REP, idev->evbit);

Ditto.

Also in lm8323_remove we need to set_irq_wake(..., 0) right?

include/linux/i2c/lm8323.h line 2

Quoted 9 lines
drivers/input/keyboard/lm8323.c new file +1 -0
+
include/linux/i2c/lm8323.h new file +2 -0
new file mode 100644
index 0000000..5eae5cc
@@ -0,0 +1,35 @@
+/*
+ * include/lm8323.h

Path problem...better to remove it.

---Trilok Soni
http://triloksoni.wordpress.com
http://www.linkedin.com/in/triloksoni

#2 lore raw

Hi,

Quoted 67 lines · Trilok Soni

Hi Flipe,

drivers/input/keyboard/lm8323.c line 4

Quoted 10 lines
drivers/input/keyboard/lm8323.c new file +4 -0
new file mode 100644
index 0000000..27da93c
@@ -0,0 +1,913 @@
+/*
+ * drivers/i2c/chips/lm8323.c
+ *
+ * Copyright (C) 2007 Nokia Corporation

You might want to update this if you have updated some code before submitting to kernel list.

drivers/input/keyboard/lm8323.c line 8

Quoted 4 lines
drivers/input/keyboard/lm8323.c new file +4 -0
+
+       err = request_irq(client->irq, lm8323_irq,
+                         IRQF_TRIGGER_FALLING | IRQF_DISABLED |
+                         IRQF_SAMPLE_RANDOM, "lm8323", lm);

No need to add IRQF_SAMPLE_RANDOM, it is done input subsystem. Please check input_report_event.

drivers/input/keyboard/lm8323.c line 10

Quoted 2 lines
drivers/input/keyboard/lm8323.c new file +2 -0
+
+       set_irq_wake(client->irq, 1);

Shall we move to device_init_wakup + enable_irq_wake friends ?

Quoted 14 lines
drivers/input/keyboard/lm8323.c new file +14 -0
+
+       lm->kp_enabled = 1;
+       err = device_create_file(&client->dev, &dev_attr_disable_kp);
+       if (err < 0)
+               goto fail7;
+
+       idev = input_allocate_device();
+       if (!idev) {
+               err = -ENOMEM;
+               goto fail8;
+       }
+
+       if (pdata->name)
+               idev->name = pdata->name;

drivers/input/keyboard/lm8323.c line 34

Quoted 10 lines
drivers/input/keyboard/lm8323.c new file +10 -0
+       else
+               idev->name = "LM8323 keypad";
+       snprintf(lm->phys, sizeof(lm->phys), "%s/input-kp", client->dev.bus_id);
+       idev->phys = lm->phys;
+
+       lm->keys_down = 0;
+       idev->evbit[0] = BIT(EV_KEY);
+       for (i = 0; i < LM8323_KEYMAP_SIZE; i++) {
+               if (pdata->keymap[i] > 0)
+                       set_bit(pdata->keymap[i], idev->keybit);

No difference but better to use __set_bit, as atomicity is not required here.

drivers/input/keyboard/lm8323.c line 40

Quoted 6 lines
drivers/input/keyboard/lm8323.c new file +6 -0
+
+               lm->keymap[i] = pdata->keymap[i];
+       }
+
+       if (pdata->repeat)
+               set_bit(EV_REP, idev->evbit);

Ditto.

Also in lm8323_remove we need to set_irq_wake(..., 0) right?

Quoted 11 lines

include/linux/i2c/lm8323.h line 2

Quoted 9 lines
drivers/input/keyboard/lm8323.c new file +1 -0
+
include/linux/i2c/lm8323.h new file +2 -0
new file mode 100644
index 0000000..5eae5cc
@@ -0,0 +1,35 @@
+/*
+ * include/lm8323.h

Path problem...better to remove it.

thanks for reviewing it, here's the updated version:

==== cut here ====

Quoted 1 line

From 1d0efd5df741526da45dde118918a9bb5ee47e6a Mon Sep 17 00:00:00 2001

From: Felipe Balbi <[email protected]>
Date: Thu, 19 Feb 2009 14:08:49 +0200
Subject: [PATCH] input: keyboard: introduce lm8323 driver

lm8323 is the keypad driver used in n810 device. This driver has been sitting in linux-omap for quite a long time, it's about time to get comments from upstream and get it merged.

---
 drivers/input/keyboard/Kconfig  |    7 +
 drivers/input/keyboard/Makefile |    1 +
 drivers/input/keyboard/lm8323.c |  917 +++++++++++++++++++++++++++++++++++++++
 include/linux/i2c/lm8323.h      |   46 ++
 4 files changed, 971 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/keyboard/lm8323.c
 create mode 100644 include/linux/i2c/lm8323.h
drivers/input/keyboard/Kconfig +7 -0
index 3556168..2da936b 100644
@@ -259,6 +259,13 @@ config KEYBOARD_OMAP
 	  To compile this driver as a module, choose M here: the
 	  module will be called omap-keypad.
 
+config KEYBOARD_LM8323
+	tristate "LM8323 keypad chip"
+	depends on I2C
+	help
+	  If you say yes here you get support for the National Semiconductor
+	  LM8323 keypad controller.
+
 config KEYBOARD_PXA27x
 	tristate "PXA27x/PXA3xx keypad support"
 	depends on PXA27x || PXA3xx
drivers/input/keyboard/Makefile +1 -0
index 36351e1..f8bf562 100644
@@ -19,6 +19,7 @@ obj-$(CONFIG_KEYBOARD_TOSA)		+= tosakbd.o
 obj-$(CONFIG_KEYBOARD_HIL)		+= hil_kbd.o
 obj-$(CONFIG_KEYBOARD_HIL_OLD)		+= hilkbd.o
 obj-$(CONFIG_KEYBOARD_OMAP)		+= omap-keypad.o
+obj-$(CONFIG_KEYBOARD_LM8323)		+= lm8323.o
 obj-$(CONFIG_KEYBOARD_PXA27x)		+= pxa27x_keypad.o
 obj-$(CONFIG_KEYBOARD_PXA930_ROTARY)	+= pxa930_rotary.o
 obj-$(CONFIG_KEYBOARD_AAED2000)		+= aaed2000_kbd.o
drivers/input/keyboard/lm8323.c new file +917 -0

917 lines not on this page · raw message

include/linux/i2c/lm8323.h new file +46 -0

46 lines not on this page · raw message

Signature · 4 lines
1.6.1.3

-- 
balbi
#3 lore raw
In reply to Felipe Balbi
Quoted 7 lines · On Thu, 19 Feb 2009 14:14:14 +0200 Felipe Balbi <[email protected]> wrote:

From: Felipe Balbi <[email protected]>

lm8323 is the keypad driver used in n810 device. This driver has been sitting in linux-omap for quite a long time, it's about time to get comments from upstream and get it merged.

Please feed it through scripts/checkpatch.pl and review the resulting report?

drivers/input/keyboard/lm8323.c line 585

Quoted 12 lines
drivers/input/keyboard/lm8323.c new file +12 -0
+static ssize_t lm8323_pwm_store_time(struct device *dev,
+		struct device_attribute *attr, const char *buf, size_t len)
+{
+	struct led_classdev *led_cdev = dev_get_drvdata(dev);
+	struct lm8323_pwm *pwm = cdev_to_pwm(led_cdev);
+	int ret;
+	int time;
+
+	ret = sscanf(buf, "%d", &time);
+	/* Numbers only, please. */
+	if (ret)
+		return -EINVAL;

strict_strtoul() does a better job of this.

Quoted 25 lines
drivers/input/keyboard/lm8323.c new file +25 -0
+	pwm->fade_time = time;
+
+	return strlen(buf);
+}
+static DEVICE_ATTR(time, 0644, lm8323_pwm_show_time, lm8323_pwm_store_time);
+
+static int init_pwm(struct lm8323_chip *lm, int id, struct device *dev,
+		    const char *name)
+{
+	struct lm8323_pwm *pwm = NULL;
+
+	BUG_ON(id > 3);
+
+	switch (id) {
+	case 1:
+		pwm = &lm->pwm1;
+		break;
+	case 2:
+		pwm = &lm->pwm2;
+		break;
+	case 3:
+		pwm = &lm->pwm3;
+		break;
+	}
+

drivers/input/keyboard/lm8323.c line 621

Quoted 10 lines
drivers/input/keyboard/lm8323.c new file +10 -0
+	pwm->id = id;
+	pwm->fade_time = 0;
+	pwm->brightness = 0;
+	pwm->desired_brightness = 0;
+	pwm->running = 0;
+	mutex_init(&pwm->lock);
+	if (name) {
+		pwm->cdev.name = name;
+		pwm->cdev.brightness_set = lm8323_pwm_set_brightness;
+		if (led_classdev_register(dev, &pwm->cdev) < 0) {

I did't see a dependency on LEDS in the Kconfig entry. Will it compile with LEDS=n?

Quoted 27 lines
drivers/input/keyboard/lm8323.c new file +27 -0
+			dev_err(dev, "couldn't register PWM %d\n", id);
+			return -1;
+		}
+		if (device_create_file(pwm->cdev.dev,
+					     &dev_attr_time) < 0) {
+			dev_err(dev, "couldn't register time attribute\n");
+			led_classdev_unregister(&pwm->cdev);
+			return -1;
+		}
+		INIT_WORK(&pwm->work, lm8323_pwm_work);
+		pwm->enabled = 1;
+	} else {
+		pwm->enabled = 0;
+	}
+
+	return 0;
+}
+
+static struct i2c_driver lm8323_i2c_driver;
+
+static ssize_t lm8323_show_disable(struct device *dev,
+				   struct device_attribute *attr, char *buf)
+{
+	struct lm8323_chip *lm = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%u\n", !lm->kp_enabled);
+}

drivers/input/keyboard/lm8323.c line 658

Quoted 10 lines
drivers/input/keyboard/lm8323.c new file +10 -0
+
+static ssize_t lm8323_set_disable(struct device *dev,
+				  struct device_attribute *attr,
+				  const char *buf, size_t count)
+{
+	struct lm8323_chip *lm = dev_get_drvdata(dev);
+	int ret;
+	int i;
+
+	i = sscanf(buf, "%d", &ret);

Again, strict_strto*() would be better. It will disallow input of the form "42foo".

Quoted 9 lines
drivers/input/keyboard/lm8323.c new file +6 -0
+	mutex_lock(&lm->lock);
+	lm->kp_enabled = !i;
+	mutex_unlock(&lm->lock);
+
+	return count;
+}
 
...
 

drivers/input/keyboard/lm8323.c line 895

Quoted 10 lines
drivers/input/keyboard/lm8323.c new file +10 -0
+static struct i2c_driver lm8323_i2c_driver = {
+	.driver = {
+		.name	 = "lm8323",
+	},
+	.probe		= lm8323_probe,
+	.remove		= lm8323_remove,
+	.suspend	= lm8323_suspend,
+	.resume		= lm8323_resume,
+	.id_table	= lm8323_id,
+};

Does this compile and run OK with CONFIG_PM=n?

Quoted 3 lines

...

#4 lore raw
Quoted 5 lines · Andrew Morton
Quoted 2 lines · On Thu, 19 Feb 2009 14:14:14 +0200 Felipe Balbi <[email protected]> wrote:

From: Felipe Balbi <[email protected]>

Quoted 8 lines
Quoted 5 lines

lm8323 is the keypad driver used in n810 device. This driver has been sitting in linux-omap for quite a long time, it's about time to get comments from upstream and get it merged.

Please feed it through scripts/checkpatch.pl and review the resulting report?

thanks a lot for reviewing this patch, here's the updated patch:

======== cut here ========

Quoted 1 line

From 916e4edef83b1f596f569f6753368e3d3328fd18 Mon Sep 17 00:00:00 2001

From: Felipe Balbi <[email protected]>
Date: Thu, 19 Feb 2009 14:08:49 +0200
Subject: [PATCH] input: keyboard: introduce lm8323 driver

lm8323 is the keypad driver used in n810 device. This driver has been sitting in linux-omap for quite a long time, it's about time to get comments from upstream and get it merged.

---
 drivers/input/keyboard/Kconfig  |    8 +
 drivers/input/keyboard/Makefile |    1 +
 drivers/input/keyboard/lm8323.c |  928 +++++++++++++++++++++++++++++++++++++++
 include/linux/i2c/lm8323.h      |   46 ++
 4 files changed, 983 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/keyboard/lm8323.c
 create mode 100644 include/linux/i2c/lm8323.h
drivers/input/keyboard/Kconfig +8 -0
index 3556168..2243391 100644
@@ -259,6 +259,14 @@ config KEYBOARD_OMAP
 	  To compile this driver as a module, choose M here: the
 	  module will be called omap-keypad.
 
+config KEYBOARD_LM8323
+	tristate "LM8323 keypad chip"
+	depends on I2C
+	depends on LEDS
+	help
+	  If you say yes here you get support for the National Semiconductor
+	  LM8323 keypad controller.
+
 config KEYBOARD_PXA27x
 	tristate "PXA27x/PXA3xx keypad support"
 	depends on PXA27x || PXA3xx
drivers/input/keyboard/Makefile +1 -0
index 36351e1..f8bf562 100644
@@ -19,6 +19,7 @@ obj-$(CONFIG_KEYBOARD_TOSA)		+= tosakbd.o
 obj-$(CONFIG_KEYBOARD_HIL)		+= hil_kbd.o
 obj-$(CONFIG_KEYBOARD_HIL_OLD)		+= hilkbd.o
 obj-$(CONFIG_KEYBOARD_OMAP)		+= omap-keypad.o
+obj-$(CONFIG_KEYBOARD_LM8323)		+= lm8323.o
 obj-$(CONFIG_KEYBOARD_PXA27x)		+= pxa27x_keypad.o
 obj-$(CONFIG_KEYBOARD_PXA930_ROTARY)	+= pxa930_rotary.o
 obj-$(CONFIG_KEYBOARD_AAED2000)		+= aaed2000_kbd.o
drivers/input/keyboard/lm8323.c new file +928 -0

928 lines not on this page · raw message

include/linux/i2c/lm8323.h new file +46 -0

46 lines not on this page · raw message

Signature · 4 lines
1.6.1.3

-- 
balbi