diff options
author | Magnus Damm <damm@opensource.se> | 2010-02-11 01:13:21 -0500 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2010-02-11 02:04:07 -0500 |
commit | 2b14a808fbbb042d0de323260d939bdf95e9efdf (patch) | |
tree | 48602ddf8851c251437d1bcf192a520da251c224 /drivers/input | |
parent | b63de38591605916fff5d483e0bedc65dfe3d395 (diff) |
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: Magnus Damm <damm@opensource.se>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input')
-rw-r--r-- | drivers/input/keyboard/sh_keysc.c | 69 |
1 files changed, 43 insertions, 26 deletions
diff --git a/drivers/input/keyboard/sh_keysc.c b/drivers/input/keyboard/sh_keysc.c index efcc3a3b9b53..6218b2f02495 100644 --- a/drivers/input/keyboard/sh_keysc.c +++ b/drivers/input/keyboard/sh_keysc.c | |||
@@ -22,14 +22,6 @@ | |||
22 | #include <linux/clk.h> | 22 | #include <linux/clk.h> |
23 | #include <linux/io.h> | 23 | #include <linux/io.h> |
24 | 24 | ||
25 | #define KYCR1_OFFS 0x00 | ||
26 | #define KYCR2_OFFS 0x04 | ||
27 | #define KYINDR_OFFS 0x08 | ||
28 | #define KYOUTDR_OFFS 0x0c | ||
29 | |||
30 | #define KYCR2_IRQ_LEVEL 0x10 | ||
31 | #define KYCR2_IRQ_DISABLED 0x00 | ||
32 | |||
33 | static const struct { | 25 | static const struct { |
34 | unsigned char kymd, keyout, keyin; | 26 | unsigned char kymd, keyout, keyin; |
35 | } sh_keysc_mode[] = { | 27 | } sh_keysc_mode[] = { |
@@ -48,6 +40,37 @@ struct sh_keysc_priv { | |||
48 | struct sh_keysc_info pdata; | 40 | struct sh_keysc_info pdata; |
49 | }; | 41 | }; |
50 | 42 | ||
43 | #define KYCR1 0 | ||
44 | #define KYCR2 1 | ||
45 | #define KYINDR 2 | ||
46 | #define KYOUTDR 3 | ||
47 | |||
48 | #define KYCR2_IRQ_LEVEL 0x10 | ||
49 | #define KYCR2_IRQ_DISABLED 0x00 | ||
50 | |||
51 | static unsigned long sh_keysc_read(struct sh_keysc_priv *p, int reg_nr) | ||
52 | { | ||
53 | return ioread16(p->iomem_base + (reg_nr << 2)); | ||
54 | } | ||
55 | |||
56 | static void sh_keysc_write(struct sh_keysc_priv *p, int reg_nr, | ||
57 | unsigned long value) | ||
58 | { | ||
59 | iowrite16(value, p->iomem_base + (reg_nr << 2)); | ||
60 | } | ||
61 | |||
62 | static void sh_keysc_level_mode(struct sh_keysc_priv *p, | ||
63 | unsigned long keys_set) | ||
64 | { | ||
65 | struct sh_keysc_info *pdata = &p->pdata; | ||
66 | |||
67 | sh_keysc_write(p, KYOUTDR, 0); | ||
68 | sh_keysc_write(p, KYCR2, KYCR2_IRQ_LEVEL | (keys_set << 8)); | ||
69 | |||
70 | if (pdata->kycr2_delay) | ||
71 | udelay(pdata->kycr2_delay); | ||
72 | } | ||
73 | |||
51 | static irqreturn_t sh_keysc_isr(int irq, void *dev_id) | 74 | static irqreturn_t sh_keysc_isr(int irq, void *dev_id) |
52 | { | 75 | { |
53 | struct platform_device *pdev = dev_id; | 76 | struct platform_device *pdev = dev_id; |
@@ -66,24 +89,19 @@ static irqreturn_t sh_keysc_isr(int irq, void *dev_id) | |||
66 | keys = 0; | 89 | keys = 0; |
67 | keyin_set = 0; | 90 | keyin_set = 0; |
68 | 91 | ||
69 | iowrite16(KYCR2_IRQ_DISABLED, priv->iomem_base + KYCR2_OFFS); | 92 | sh_keysc_write(priv, KYCR2, KYCR2_IRQ_DISABLED); |
70 | 93 | ||
71 | for (i = 0; i < sh_keysc_mode[pdata->mode].keyout; i++) { | 94 | for (i = 0; i < sh_keysc_mode[pdata->mode].keyout; i++) { |
72 | iowrite16(0xfff ^ (3 << (i * 2)), | 95 | sh_keysc_write(priv, KYOUTDR, 0xfff ^ (3 << (i * 2))); |
73 | priv->iomem_base + KYOUTDR_OFFS); | ||
74 | udelay(pdata->delay); | 96 | udelay(pdata->delay); |
75 | tmp = ioread16(priv->iomem_base + KYINDR_OFFS); | 97 | tmp = sh_keysc_read(priv, KYINDR); |
98 | |||
76 | keys |= tmp << (sh_keysc_mode[pdata->mode].keyin * i); | 99 | keys |= tmp << (sh_keysc_mode[pdata->mode].keyin * i); |
77 | tmp ^= (1 << sh_keysc_mode[pdata->mode].keyin) - 1; | 100 | tmp ^= (1 << sh_keysc_mode[pdata->mode].keyin) - 1; |
78 | keyin_set |= tmp; | 101 | keyin_set |= tmp; |
79 | } | 102 | } |
80 | 103 | ||
81 | iowrite16(0, priv->iomem_base + KYOUTDR_OFFS); | 104 | sh_keysc_level_mode(priv, keyin_set); |
82 | iowrite16(KYCR2_IRQ_LEVEL | (keyin_set << 8), | ||
83 | priv->iomem_base + KYCR2_OFFS); | ||
84 | |||
85 | if (pdata->kycr2_delay) | ||
86 | udelay(pdata->kycr2_delay); | ||
87 | 105 | ||
88 | keys ^= ~0; | 106 | keys ^= ~0; |
89 | keys &= (1 << (sh_keysc_mode[pdata->mode].keyin * | 107 | keys &= (1 << (sh_keysc_mode[pdata->mode].keyin * |
@@ -93,7 +111,7 @@ static irqreturn_t sh_keysc_isr(int irq, void *dev_id) | |||
93 | 111 | ||
94 | dev_dbg(&pdev->dev, "keys 0x%08lx\n", keys); | 112 | dev_dbg(&pdev->dev, "keys 0x%08lx\n", keys); |
95 | 113 | ||
96 | } while (ioread16(priv->iomem_base + KYCR2_OFFS) & 0x01); | 114 | } while (sh_keysc_read(priv, KYCR2) & 0x01); |
97 | 115 | ||
98 | dev_dbg(&pdev->dev, "last_keys 0x%08lx keys0 0x%08lx keys1 0x%08lx\n", | 116 | dev_dbg(&pdev->dev, "last_keys 0x%08lx keys0 0x%08lx keys1 0x%08lx\n", |
99 | priv->last_keys, keys0, keys1); | 117 | priv->last_keys, keys0, keys1); |
@@ -220,10 +238,9 @@ static int __devinit sh_keysc_probe(struct platform_device *pdev) | |||
220 | 238 | ||
221 | clk_enable(priv->clk); | 239 | clk_enable(priv->clk); |
222 | 240 | ||
223 | iowrite16((sh_keysc_mode[pdata->mode].kymd << 8) | | 241 | sh_keysc_write(priv, KYCR1, (sh_keysc_mode[pdata->mode].kymd << 8) | |
224 | pdata->scan_timing, priv->iomem_base + KYCR1_OFFS); | 242 | pdata->scan_timing); |
225 | iowrite16(0, priv->iomem_base + KYOUTDR_OFFS); | 243 | sh_keysc_level_mode(priv, 0); |
226 | iowrite16(KYCR2_IRQ_LEVEL, priv->iomem_base + KYCR2_OFFS); | ||
227 | 244 | ||
228 | device_init_wakeup(&pdev->dev, 1); | 245 | device_init_wakeup(&pdev->dev, 1); |
229 | 246 | ||
@@ -248,7 +265,7 @@ static int __devexit sh_keysc_remove(struct platform_device *pdev) | |||
248 | { | 265 | { |
249 | struct sh_keysc_priv *priv = platform_get_drvdata(pdev); | 266 | struct sh_keysc_priv *priv = platform_get_drvdata(pdev); |
250 | 267 | ||
251 | iowrite16(KYCR2_IRQ_DISABLED, priv->iomem_base + KYCR2_OFFS); | 268 | sh_keysc_write(priv, KYCR2, KYCR2_IRQ_DISABLED); |
252 | 269 | ||
253 | input_unregister_device(priv->input); | 270 | input_unregister_device(priv->input); |
254 | free_irq(platform_get_irq(pdev, 0), pdev); | 271 | free_irq(platform_get_irq(pdev, 0), pdev); |
@@ -270,7 +287,7 @@ static int sh_keysc_suspend(struct device *dev) | |||
270 | int irq = platform_get_irq(pdev, 0); | 287 | int irq = platform_get_irq(pdev, 0); |
271 | unsigned short value; | 288 | unsigned short value; |
272 | 289 | ||
273 | value = ioread16(priv->iomem_base + KYCR1_OFFS); | 290 | value = sh_keysc_read(priv, KYCR1); |
274 | 291 | ||
275 | if (device_may_wakeup(dev)) { | 292 | if (device_may_wakeup(dev)) { |
276 | value |= 0x80; | 293 | value |= 0x80; |
@@ -279,7 +296,7 @@ static int sh_keysc_suspend(struct device *dev) | |||
279 | value &= ~0x80; | 296 | value &= ~0x80; |
280 | } | 297 | } |
281 | 298 | ||
282 | iowrite16(value, priv->iomem_base + KYCR1_OFFS); | 299 | sh_keysc_write(priv, KYCR1, value); |
283 | 300 | ||
284 | return 0; | 301 | return 0; |
285 | } | 302 | } |