Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 183125
b: refs/heads/master
c: 2b14a80
h: refs/heads/master
i:
  183123: b6264ef
v: v3
  • Loading branch information
Magnus Damm authored and Dmitry Torokhov committed Feb 11, 2010
1 parent 9c532df commit a0c2430
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 27 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: b63de38591605916fff5d483e0bedc65dfe3d395
refs/heads/master: 2b14a808fbbb042d0de323260d939bdf95e9efdf
69 changes: 43 additions & 26 deletions trunk/drivers/input/keyboard/sh_keysc.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@
#include <linux/clk.h>
#include <linux/io.h>

#define KYCR1_OFFS 0x00
#define KYCR2_OFFS 0x04
#define KYINDR_OFFS 0x08
#define KYOUTDR_OFFS 0x0c

#define KYCR2_IRQ_LEVEL 0x10
#define KYCR2_IRQ_DISABLED 0x00

static const struct {
unsigned char kymd, keyout, keyin;
} sh_keysc_mode[] = {
Expand All @@ -48,6 +40,37 @@ struct sh_keysc_priv {
struct sh_keysc_info pdata;
};

#define KYCR1 0
#define KYCR2 1
#define KYINDR 2
#define KYOUTDR 3

#define KYCR2_IRQ_LEVEL 0x10
#define KYCR2_IRQ_DISABLED 0x00

static unsigned long sh_keysc_read(struct sh_keysc_priv *p, int reg_nr)
{
return ioread16(p->iomem_base + (reg_nr << 2));
}

static void sh_keysc_write(struct sh_keysc_priv *p, int reg_nr,
unsigned long value)
{
iowrite16(value, p->iomem_base + (reg_nr << 2));
}

static void sh_keysc_level_mode(struct sh_keysc_priv *p,
unsigned long keys_set)
{
struct sh_keysc_info *pdata = &p->pdata;

sh_keysc_write(p, KYOUTDR, 0);
sh_keysc_write(p, KYCR2, KYCR2_IRQ_LEVEL | (keys_set << 8));

if (pdata->kycr2_delay)
udelay(pdata->kycr2_delay);
}

static irqreturn_t sh_keysc_isr(int irq, void *dev_id)
{
struct platform_device *pdev = dev_id;
Expand All @@ -66,24 +89,19 @@ static irqreturn_t sh_keysc_isr(int irq, void *dev_id)
keys = 0;
keyin_set = 0;

iowrite16(KYCR2_IRQ_DISABLED, priv->iomem_base + KYCR2_OFFS);
sh_keysc_write(priv, KYCR2, KYCR2_IRQ_DISABLED);

for (i = 0; i < sh_keysc_mode[pdata->mode].keyout; i++) {
iowrite16(0xfff ^ (3 << (i * 2)),
priv->iomem_base + KYOUTDR_OFFS);
sh_keysc_write(priv, KYOUTDR, 0xfff ^ (3 << (i * 2)));
udelay(pdata->delay);
tmp = ioread16(priv->iomem_base + KYINDR_OFFS);
tmp = sh_keysc_read(priv, KYINDR);

keys |= tmp << (sh_keysc_mode[pdata->mode].keyin * i);
tmp ^= (1 << sh_keysc_mode[pdata->mode].keyin) - 1;
keyin_set |= tmp;
}

iowrite16(0, priv->iomem_base + KYOUTDR_OFFS);
iowrite16(KYCR2_IRQ_LEVEL | (keyin_set << 8),
priv->iomem_base + KYCR2_OFFS);

if (pdata->kycr2_delay)
udelay(pdata->kycr2_delay);
sh_keysc_level_mode(priv, keyin_set);

keys ^= ~0;
keys &= (1 << (sh_keysc_mode[pdata->mode].keyin *
Expand All @@ -93,7 +111,7 @@ static irqreturn_t sh_keysc_isr(int irq, void *dev_id)

dev_dbg(&pdev->dev, "keys 0x%08lx\n", keys);

} while (ioread16(priv->iomem_base + KYCR2_OFFS) & 0x01);
} while (sh_keysc_read(priv, KYCR2) & 0x01);

dev_dbg(&pdev->dev, "last_keys 0x%08lx keys0 0x%08lx keys1 0x%08lx\n",
priv->last_keys, keys0, keys1);
Expand Down Expand Up @@ -220,10 +238,9 @@ static int __devinit sh_keysc_probe(struct platform_device *pdev)

clk_enable(priv->clk);

iowrite16((sh_keysc_mode[pdata->mode].kymd << 8) |
pdata->scan_timing, priv->iomem_base + KYCR1_OFFS);
iowrite16(0, priv->iomem_base + KYOUTDR_OFFS);
iowrite16(KYCR2_IRQ_LEVEL, priv->iomem_base + KYCR2_OFFS);
sh_keysc_write(priv, KYCR1, (sh_keysc_mode[pdata->mode].kymd << 8) |
pdata->scan_timing);
sh_keysc_level_mode(priv, 0);

device_init_wakeup(&pdev->dev, 1);

Expand All @@ -248,7 +265,7 @@ static int __devexit sh_keysc_remove(struct platform_device *pdev)
{
struct sh_keysc_priv *priv = platform_get_drvdata(pdev);

iowrite16(KYCR2_IRQ_DISABLED, priv->iomem_base + KYCR2_OFFS);
sh_keysc_write(priv, KYCR2, KYCR2_IRQ_DISABLED);

input_unregister_device(priv->input);
free_irq(platform_get_irq(pdev, 0), pdev);
Expand All @@ -270,7 +287,7 @@ static int sh_keysc_suspend(struct device *dev)
int irq = platform_get_irq(pdev, 0);
unsigned short value;

value = ioread16(priv->iomem_base + KYCR1_OFFS);
value = sh_keysc_read(priv, KYCR1);

if (device_may_wakeup(dev)) {
value |= 0x80;
Expand All @@ -279,7 +296,7 @@ static int sh_keysc_suspend(struct device *dev)
value &= ~0x80;
}

iowrite16(value, priv->iomem_base + KYCR1_OFFS);
sh_keysc_write(priv, KYCR1, value);

return 0;
}
Expand Down

0 comments on commit a0c2430

Please sign in to comment.