Commit 324e5ade authored by Magnus Damm's avatar Magnus Damm Committed by Dmitry Torokhov

Input: sh_keysc - switch to using bitmaps

Use bitmaps instead of using 32-bit integers to keep track of the key
states. With this change in place the driver supports key pads with
more than 32 keys.
Signed-off-by: default avatarMagnus Damm <damm@opensource.se>
Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
parent 2b14a808
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/input.h> #include <linux/input.h>
#include <linux/input/sh_keysc.h> #include <linux/input/sh_keysc.h>
#include <linux/bitmap.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/io.h> #include <linux/io.h>
...@@ -35,7 +36,7 @@ static const struct { ...@@ -35,7 +36,7 @@ static const struct {
struct sh_keysc_priv { struct sh_keysc_priv {
void __iomem *iomem_base; void __iomem *iomem_base;
struct clk *clk; struct clk *clk;
unsigned long last_keys; DECLARE_BITMAP(last_keys, SH_KEYSC_MAXKEYS);
struct input_dev *input; struct input_dev *input;
struct sh_keysc_info pdata; struct sh_keysc_info pdata;
}; };
...@@ -71,69 +72,87 @@ static void sh_keysc_level_mode(struct sh_keysc_priv *p, ...@@ -71,69 +72,87 @@ static void sh_keysc_level_mode(struct sh_keysc_priv *p,
udelay(pdata->kycr2_delay); udelay(pdata->kycr2_delay);
} }
static void sh_keysc_map_dbg(struct device *dev, unsigned long *map,
const char *str)
{
int k;
for (k = 0; k < BITS_TO_LONGS(SH_KEYSC_MAXKEYS); k++)
dev_dbg(dev, "%s[%d] 0x%lx\n", str, k, map[k]);
}
static irqreturn_t sh_keysc_isr(int irq, void *dev_id) static irqreturn_t sh_keysc_isr(int irq, void *dev_id)
{ {
struct platform_device *pdev = dev_id; struct platform_device *pdev = dev_id;
struct sh_keysc_priv *priv = platform_get_drvdata(pdev); struct sh_keysc_priv *priv = platform_get_drvdata(pdev);
struct sh_keysc_info *pdata = &priv->pdata; struct sh_keysc_info *pdata = &priv->pdata;
unsigned long keys, keys1, keys0, mask; int keyout_nr = sh_keysc_mode[pdata->mode].keyout;
int keyin_nr = sh_keysc_mode[pdata->mode].keyin;
DECLARE_BITMAP(keys, SH_KEYSC_MAXKEYS);
DECLARE_BITMAP(keys0, SH_KEYSC_MAXKEYS);
DECLARE_BITMAP(keys1, SH_KEYSC_MAXKEYS);
unsigned char keyin_set, tmp; unsigned char keyin_set, tmp;
int i, k; int i, k, n;
dev_dbg(&pdev->dev, "isr!\n"); dev_dbg(&pdev->dev, "isr!\n");
keys1 = ~0; bitmap_fill(keys1, SH_KEYSC_MAXKEYS);
keys0 = 0; bitmap_zero(keys0, SH_KEYSC_MAXKEYS);
do { do {
keys = 0; bitmap_zero(keys, SH_KEYSC_MAXKEYS);
keyin_set = 0; keyin_set = 0;
sh_keysc_write(priv, KYCR2, KYCR2_IRQ_DISABLED); sh_keysc_write(priv, KYCR2, KYCR2_IRQ_DISABLED);
for (i = 0; i < sh_keysc_mode[pdata->mode].keyout; i++) { for (i = 0; i < keyout_nr; i++) {
n = keyin_nr * i;
/* drive one KEYOUT pin low, read KEYIN pins */
sh_keysc_write(priv, KYOUTDR, 0xfff ^ (3 << (i * 2))); sh_keysc_write(priv, KYOUTDR, 0xfff ^ (3 << (i * 2)));
udelay(pdata->delay); udelay(pdata->delay);
tmp = sh_keysc_read(priv, KYINDR); tmp = sh_keysc_read(priv, KYINDR);
keys |= tmp << (sh_keysc_mode[pdata->mode].keyin * i); /* set bit if key press has been detected */
tmp ^= (1 << sh_keysc_mode[pdata->mode].keyin) - 1; for (k = 0; k < keyin_nr; k++) {
keyin_set |= tmp; if (tmp & (1 << k))
__set_bit(n + k, keys);
}
/* keep track of which KEYIN bits that have been set */
keyin_set |= tmp ^ ((1 << keyin_nr) - 1);
} }
sh_keysc_level_mode(priv, keyin_set); sh_keysc_level_mode(priv, keyin_set);
keys ^= ~0; bitmap_complement(keys, keys, SH_KEYSC_MAXKEYS);
keys &= (1 << (sh_keysc_mode[pdata->mode].keyin * bitmap_and(keys1, keys1, keys, SH_KEYSC_MAXKEYS);
sh_keysc_mode[pdata->mode].keyout)) - 1; bitmap_or(keys0, keys0, keys, SH_KEYSC_MAXKEYS);
keys1 &= keys;
keys0 |= keys;
dev_dbg(&pdev->dev, "keys 0x%08lx\n", keys); sh_keysc_map_dbg(&pdev->dev, keys, "keys");
} while (sh_keysc_read(priv, KYCR2) & 0x01); } while (sh_keysc_read(priv, KYCR2) & 0x01);
dev_dbg(&pdev->dev, "last_keys 0x%08lx keys0 0x%08lx keys1 0x%08lx\n", sh_keysc_map_dbg(&pdev->dev, priv->last_keys, "last_keys");
priv->last_keys, keys0, keys1); sh_keysc_map_dbg(&pdev->dev, keys0, "keys0");
sh_keysc_map_dbg(&pdev->dev, keys1, "keys1");
for (i = 0; i < SH_KEYSC_MAXKEYS; i++) { for (i = 0; i < SH_KEYSC_MAXKEYS; i++) {
k = pdata->keycodes[i]; k = pdata->keycodes[i];
if (!k) if (!k)
continue; continue;
mask = 1 << i; if (test_bit(i, keys0) == test_bit(i, priv->last_keys))
if (!((priv->last_keys ^ keys0) & mask))
continue; continue;
if ((keys1 | keys0) & mask) { if (test_bit(i, keys1) || test_bit(i, keys0)) {
input_event(priv->input, EV_KEY, k, 1); input_event(priv->input, EV_KEY, k, 1);
priv->last_keys |= mask; __set_bit(i, priv->last_keys);
} }
if (!(keys1 & mask)) { if (!test_bit(i, keys1)) {
input_event(priv->input, EV_KEY, k, 0); input_event(priv->input, EV_KEY, k, 0);
priv->last_keys &= ~mask; __clear_bit(i, priv->last_keys);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment