提交 2b14a808 编写于 作者: M Magnus Damm 提交者: Dmitry Torokhov

Input: sh_keysc - factor out hw access functions

Update the sh_keysc driver to factor out the register access functions
sh_keysc_read(), sh_keysc_write() together with sh_keysc_level_mode().
This makes the code a bit easier to follow.
Signed-off-by: NMagnus Damm <damm@opensource.se>
Signed-off-by: NDmitry Torokhov <dtor@mail.ru>
上级 b63de385
...@@ -22,14 +22,6 @@ ...@@ -22,14 +22,6 @@
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/io.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 { static const struct {
unsigned char kymd, keyout, keyin; unsigned char kymd, keyout, keyin;
} sh_keysc_mode[] = { } sh_keysc_mode[] = {
...@@ -48,6 +40,37 @@ struct sh_keysc_priv { ...@@ -48,6 +40,37 @@ struct sh_keysc_priv {
struct sh_keysc_info pdata; 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) static irqreturn_t sh_keysc_isr(int irq, void *dev_id)
{ {
struct platform_device *pdev = dev_id; struct platform_device *pdev = dev_id;
...@@ -66,24 +89,19 @@ static irqreturn_t sh_keysc_isr(int irq, void *dev_id) ...@@ -66,24 +89,19 @@ static irqreturn_t sh_keysc_isr(int irq, void *dev_id)
keys = 0; keys = 0;
keyin_set = 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++) { for (i = 0; i < sh_keysc_mode[pdata->mode].keyout; i++) {
iowrite16(0xfff ^ (3 << (i * 2)), sh_keysc_write(priv, KYOUTDR, 0xfff ^ (3 << (i * 2)));
priv->iomem_base + KYOUTDR_OFFS);
udelay(pdata->delay); 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); keys |= tmp << (sh_keysc_mode[pdata->mode].keyin * i);
tmp ^= (1 << sh_keysc_mode[pdata->mode].keyin) - 1; tmp ^= (1 << sh_keysc_mode[pdata->mode].keyin) - 1;
keyin_set |= tmp; keyin_set |= tmp;
} }
iowrite16(0, priv->iomem_base + KYOUTDR_OFFS); sh_keysc_level_mode(priv, keyin_set);
iowrite16(KYCR2_IRQ_LEVEL | (keyin_set << 8),
priv->iomem_base + KYCR2_OFFS);
if (pdata->kycr2_delay)
udelay(pdata->kycr2_delay);
keys ^= ~0; keys ^= ~0;
keys &= (1 << (sh_keysc_mode[pdata->mode].keyin * keys &= (1 << (sh_keysc_mode[pdata->mode].keyin *
...@@ -93,7 +111,7 @@ static irqreturn_t sh_keysc_isr(int irq, void *dev_id) ...@@ -93,7 +111,7 @@ static irqreturn_t sh_keysc_isr(int irq, void *dev_id)
dev_dbg(&pdev->dev, "keys 0x%08lx\n", keys); 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", dev_dbg(&pdev->dev, "last_keys 0x%08lx keys0 0x%08lx keys1 0x%08lx\n",
priv->last_keys, keys0, keys1); priv->last_keys, keys0, keys1);
...@@ -220,10 +238,9 @@ static int __devinit sh_keysc_probe(struct platform_device *pdev) ...@@ -220,10 +238,9 @@ static int __devinit sh_keysc_probe(struct platform_device *pdev)
clk_enable(priv->clk); clk_enable(priv->clk);
iowrite16((sh_keysc_mode[pdata->mode].kymd << 8) | sh_keysc_write(priv, KYCR1, (sh_keysc_mode[pdata->mode].kymd << 8) |
pdata->scan_timing, priv->iomem_base + KYCR1_OFFS); pdata->scan_timing);
iowrite16(0, priv->iomem_base + KYOUTDR_OFFS); sh_keysc_level_mode(priv, 0);
iowrite16(KYCR2_IRQ_LEVEL, priv->iomem_base + KYCR2_OFFS);
device_init_wakeup(&pdev->dev, 1); device_init_wakeup(&pdev->dev, 1);
...@@ -248,7 +265,7 @@ static int __devexit sh_keysc_remove(struct platform_device *pdev) ...@@ -248,7 +265,7 @@ static int __devexit sh_keysc_remove(struct platform_device *pdev)
{ {
struct sh_keysc_priv *priv = platform_get_drvdata(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); input_unregister_device(priv->input);
free_irq(platform_get_irq(pdev, 0), pdev); free_irq(platform_get_irq(pdev, 0), pdev);
...@@ -270,7 +287,7 @@ static int sh_keysc_suspend(struct device *dev) ...@@ -270,7 +287,7 @@ static int sh_keysc_suspend(struct device *dev)
int irq = platform_get_irq(pdev, 0); int irq = platform_get_irq(pdev, 0);
unsigned short value; unsigned short value;
value = ioread16(priv->iomem_base + KYCR1_OFFS); value = sh_keysc_read(priv, KYCR1);
if (device_may_wakeup(dev)) { if (device_may_wakeup(dev)) {
value |= 0x80; value |= 0x80;
...@@ -279,7 +296,7 @@ static int sh_keysc_suspend(struct device *dev) ...@@ -279,7 +296,7 @@ static int sh_keysc_suspend(struct device *dev)
value &= ~0x80; value &= ~0x80;
} }
iowrite16(value, priv->iomem_base + KYCR1_OFFS); sh_keysc_write(priv, KYCR1, value);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册