13 #include <linux/kernel.h>
14 #include <linux/module.h>
20 #include <linux/input.h>
22 #include <linux/bitmap.h>
25 #include <linux/slab.h>
30 [SH_KEYSC_MODE_1] = { 0, 6, 5 },
31 [SH_KEYSC_MODE_2] = { 1, 5, 6 },
32 [SH_KEYSC_MODE_3] = { 2, 4, 7 },
33 [SH_KEYSC_MODE_4] = { 3, 6, 6 },
34 [SH_KEYSC_MODE_5] = { 4, 6, 7 },
35 [SH_KEYSC_MODE_6] = { 5, 8, 8 },
50 #define KYCR2_IRQ_LEVEL 0x10
51 #define KYCR2_IRQ_DISABLED 0x00
53 static unsigned long sh_keysc_read(
struct sh_keysc_priv *
p,
int reg_nr)
65 unsigned long keys_set)
76 static void sh_keysc_map_dbg(
struct device *
dev,
unsigned long *
map,
82 dev_dbg(dev,
"%s[%d] 0x%lx\n", str, k, map[k]);
90 int keyout_nr = sh_keysc_mode[pdata->
mode].keyout;
91 int keyin_nr = sh_keysc_mode[pdata->
mode].keyin;
95 unsigned char keyin_set,
tmp;
109 for (i = 0; i < keyout_nr; i++) {
113 sh_keysc_write(priv,
KYOUTDR, 0xffff ^ (3 << (i * 2)));
115 tmp = sh_keysc_read(priv,
KYINDR);
118 for (k = 0; k < keyin_nr; k++) {
124 keyin_set |= tmp ^ ((1 << keyin_nr) - 1);
127 sh_keysc_level_mode(priv, keyin_set);
133 sh_keysc_map_dbg(&pdev->
dev, keys,
"keys");
135 }
while (sh_keysc_read(priv,
KYCR2) & 0x01);
137 sh_keysc_map_dbg(&pdev->
dev, priv->last_keys,
"last_keys");
138 sh_keysc_map_dbg(&pdev->
dev, keys0,
"keys0");
139 sh_keysc_map_dbg(&pdev->
dev, keys1,
"keys1");
160 input_sync(priv->
input);
170 struct input_dev *
input;
174 if (!pdev->
dev.platform_data) {
175 dev_err(&pdev->
dev,
"no platform data defined\n");
183 dev_err(&pdev->
dev,
"failed to get I/O memory\n");
195 dev_err(&pdev->
dev,
"failed to allocate driver data\n");
200 platform_set_drvdata(pdev, priv);
202 pdata = &priv->
pdata;
206 dev_err(&pdev->
dev,
"failed to remap I/O memory\n");
211 priv->
input = input_allocate_device();
213 dev_err(&pdev->
dev,
"failed to allocate input device\n");
221 input->name = pdev->
name;
222 input->phys =
"sh-keysc-keys/input0";
223 input->dev.parent = &pdev->
dev;
226 input->id.vendor = 0x0001;
227 input->id.product = 0x0001;
228 input->id.version = 0x0100;
231 input->keycodesize =
sizeof(pdata->
keycodes[0]);
235 dev_name(&pdev->
dev), pdev);
237 dev_err(&pdev->
dev,
"failed to request IRQ\n");
245 error = input_register_device(input);
247 dev_err(&pdev->
dev,
"failed to register input device\n");
252 pm_runtime_get_sync(&pdev->
dev);
254 sh_keysc_write(priv,
KYCR1, (sh_keysc_mode[pdata->
mode].kymd << 8) |
256 sh_keysc_level_mode(priv, 0);
265 input_free_device(input);
269 platform_set_drvdata(pdev,
NULL);
281 input_unregister_device(priv->
input);
285 pm_runtime_put_sync(&pdev->
dev);
286 pm_runtime_disable(&pdev->
dev);
288 platform_set_drvdata(pdev,
NULL);
294 #ifdef CONFIG_PM_SLEEP
295 static int sh_keysc_suspend(
struct device *dev)
300 unsigned short value;
302 value = sh_keysc_read(priv,
KYCR1);
304 if (device_may_wakeup(dev)) {
305 sh_keysc_write(priv,
KYCR1, value | 0x80);
306 enable_irq_wake(irq);
308 sh_keysc_write(priv,
KYCR1, value & ~0x80);
309 pm_runtime_put_sync(dev);
315 static int sh_keysc_resume(
struct device *dev)
320 if (device_may_wakeup(dev))
321 disable_irq_wake(irq);
323 pm_runtime_get_sync(dev);
330 sh_keysc_suspend, sh_keysc_resume);
333 .probe = sh_keysc_probe,
337 .pm = &sh_keysc_dev_pm_ops,