Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * SuperH KEYSC Keypad Driver |
| 3 | * |
| 4 | * Copyright (C) 2008 Magnus Damm |
| 5 | * |
| 6 | * Based on gpio_keys.c, Copyright 2005 Phil Blundell |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/irq.h> |
| 18 | #include <linux/delay.h> |
| 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/input.h> |
Magnus Damm | fc1d003 | 2009-11-27 07:32:24 +0000 | [diff] [blame] | 21 | #include <linux/input/sh_keysc.h> |
Magnus Damm | 324e5ad | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 22 | #include <linux/bitmap.h> |
Magnus Damm | b6d2a3e | 2011-04-28 09:32:44 -0700 | [diff] [blame] | 23 | #include <linux/pm_runtime.h> |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 24 | #include <linux/io.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 26 | |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 27 | static const struct { |
| 28 | unsigned char kymd, keyout, keyin; |
| 29 | } sh_keysc_mode[] = { |
| 30 | [SH_KEYSC_MODE_1] = { 0, 6, 5 }, |
| 31 | [SH_KEYSC_MODE_2] = { 1, 5, 6 }, |
| 32 | [SH_KEYSC_MODE_3] = { 2, 4, 7 }, |
Magnus Damm | 3bf1276 | 2010-01-21 00:02:36 -0800 | [diff] [blame] | 33 | [SH_KEYSC_MODE_4] = { 3, 6, 6 }, |
| 34 | [SH_KEYSC_MODE_5] = { 4, 6, 7 }, |
Magnus Damm | cca23d0 | 2011-06-18 02:51:52 -0700 | [diff] [blame] | 35 | [SH_KEYSC_MODE_6] = { 5, 8, 8 }, |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | struct sh_keysc_priv { |
| 39 | void __iomem *iomem_base; |
Magnus Damm | 324e5ad | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 40 | DECLARE_BITMAP(last_keys, SH_KEYSC_MAXKEYS); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 41 | struct input_dev *input; |
| 42 | struct sh_keysc_info pdata; |
| 43 | }; |
| 44 | |
Magnus Damm | 2b14a80 | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 45 | #define KYCR1 0 |
| 46 | #define KYCR2 1 |
| 47 | #define KYINDR 2 |
| 48 | #define KYOUTDR 3 |
| 49 | |
| 50 | #define KYCR2_IRQ_LEVEL 0x10 |
| 51 | #define KYCR2_IRQ_DISABLED 0x00 |
| 52 | |
| 53 | static unsigned long sh_keysc_read(struct sh_keysc_priv *p, int reg_nr) |
| 54 | { |
| 55 | return ioread16(p->iomem_base + (reg_nr << 2)); |
| 56 | } |
| 57 | |
| 58 | static void sh_keysc_write(struct sh_keysc_priv *p, int reg_nr, |
| 59 | unsigned long value) |
| 60 | { |
| 61 | iowrite16(value, p->iomem_base + (reg_nr << 2)); |
| 62 | } |
| 63 | |
| 64 | static void sh_keysc_level_mode(struct sh_keysc_priv *p, |
| 65 | unsigned long keys_set) |
| 66 | { |
| 67 | struct sh_keysc_info *pdata = &p->pdata; |
| 68 | |
| 69 | sh_keysc_write(p, KYOUTDR, 0); |
| 70 | sh_keysc_write(p, KYCR2, KYCR2_IRQ_LEVEL | (keys_set << 8)); |
| 71 | |
| 72 | if (pdata->kycr2_delay) |
| 73 | udelay(pdata->kycr2_delay); |
| 74 | } |
| 75 | |
Magnus Damm | 324e5ad | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 76 | static void sh_keysc_map_dbg(struct device *dev, unsigned long *map, |
| 77 | const char *str) |
| 78 | { |
| 79 | int k; |
| 80 | |
| 81 | for (k = 0; k < BITS_TO_LONGS(SH_KEYSC_MAXKEYS); k++) |
| 82 | dev_dbg(dev, "%s[%d] 0x%lx\n", str, k, map[k]); |
| 83 | } |
| 84 | |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 85 | static irqreturn_t sh_keysc_isr(int irq, void *dev_id) |
| 86 | { |
| 87 | struct platform_device *pdev = dev_id; |
| 88 | struct sh_keysc_priv *priv = platform_get_drvdata(pdev); |
| 89 | struct sh_keysc_info *pdata = &priv->pdata; |
Magnus Damm | 324e5ad | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 90 | int keyout_nr = sh_keysc_mode[pdata->mode].keyout; |
| 91 | int keyin_nr = sh_keysc_mode[pdata->mode].keyin; |
| 92 | DECLARE_BITMAP(keys, SH_KEYSC_MAXKEYS); |
| 93 | DECLARE_BITMAP(keys0, SH_KEYSC_MAXKEYS); |
| 94 | DECLARE_BITMAP(keys1, SH_KEYSC_MAXKEYS); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 95 | unsigned char keyin_set, tmp; |
Magnus Damm | 324e5ad | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 96 | int i, k, n; |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 97 | |
| 98 | dev_dbg(&pdev->dev, "isr!\n"); |
| 99 | |
Magnus Damm | 324e5ad | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 100 | bitmap_fill(keys1, SH_KEYSC_MAXKEYS); |
| 101 | bitmap_zero(keys0, SH_KEYSC_MAXKEYS); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 102 | |
| 103 | do { |
Magnus Damm | 324e5ad | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 104 | bitmap_zero(keys, SH_KEYSC_MAXKEYS); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 105 | keyin_set = 0; |
| 106 | |
Magnus Damm | 2b14a80 | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 107 | sh_keysc_write(priv, KYCR2, KYCR2_IRQ_DISABLED); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 108 | |
Magnus Damm | 324e5ad | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 109 | for (i = 0; i < keyout_nr; i++) { |
| 110 | n = keyin_nr * i; |
| 111 | |
| 112 | /* drive one KEYOUT pin low, read KEYIN pins */ |
Magnus Damm | 8f8be24 | 2010-02-10 23:03:22 -0800 | [diff] [blame] | 113 | sh_keysc_write(priv, KYOUTDR, 0xffff ^ (3 << (i * 2))); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 114 | udelay(pdata->delay); |
Magnus Damm | 2b14a80 | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 115 | tmp = sh_keysc_read(priv, KYINDR); |
| 116 | |
Magnus Damm | 324e5ad | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 117 | /* set bit if key press has been detected */ |
| 118 | for (k = 0; k < keyin_nr; k++) { |
| 119 | if (tmp & (1 << k)) |
| 120 | __set_bit(n + k, keys); |
| 121 | } |
| 122 | |
| 123 | /* keep track of which KEYIN bits that have been set */ |
| 124 | keyin_set |= tmp ^ ((1 << keyin_nr) - 1); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 125 | } |
| 126 | |
Magnus Damm | 2b14a80 | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 127 | sh_keysc_level_mode(priv, keyin_set); |
Kuninori Morimoto | 1f85d38 | 2009-09-15 00:21:34 +0000 | [diff] [blame] | 128 | |
Magnus Damm | 324e5ad | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 129 | bitmap_complement(keys, keys, SH_KEYSC_MAXKEYS); |
| 130 | bitmap_and(keys1, keys1, keys, SH_KEYSC_MAXKEYS); |
| 131 | bitmap_or(keys0, keys0, keys, SH_KEYSC_MAXKEYS); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 132 | |
Magnus Damm | 324e5ad | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 133 | sh_keysc_map_dbg(&pdev->dev, keys, "keys"); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 134 | |
Magnus Damm | 2b14a80 | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 135 | } while (sh_keysc_read(priv, KYCR2) & 0x01); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 136 | |
Magnus Damm | 324e5ad | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 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"); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 140 | |
| 141 | for (i = 0; i < SH_KEYSC_MAXKEYS; i++) { |
| 142 | k = pdata->keycodes[i]; |
| 143 | if (!k) |
| 144 | continue; |
| 145 | |
Magnus Damm | 324e5ad | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 146 | if (test_bit(i, keys0) == test_bit(i, priv->last_keys)) |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 147 | continue; |
| 148 | |
Magnus Damm | 324e5ad | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 149 | if (test_bit(i, keys1) || test_bit(i, keys0)) { |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 150 | input_event(priv->input, EV_KEY, k, 1); |
Magnus Damm | 324e5ad | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 151 | __set_bit(i, priv->last_keys); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 152 | } |
| 153 | |
Magnus Damm | 324e5ad | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 154 | if (!test_bit(i, keys1)) { |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 155 | input_event(priv->input, EV_KEY, k, 0); |
Magnus Damm | 324e5ad | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 156 | __clear_bit(i, priv->last_keys); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | } |
| 160 | input_sync(priv->input); |
| 161 | |
| 162 | return IRQ_HANDLED; |
| 163 | } |
| 164 | |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 165 | static int __devinit sh_keysc_probe(struct platform_device *pdev) |
| 166 | { |
| 167 | struct sh_keysc_priv *priv; |
| 168 | struct sh_keysc_info *pdata; |
| 169 | struct resource *res; |
| 170 | struct input_dev *input; |
Dmitry Torokhov | 24d01c0 | 2009-07-21 01:12:12 -0700 | [diff] [blame] | 171 | int i; |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 172 | int irq, error; |
| 173 | |
| 174 | if (!pdev->dev.platform_data) { |
| 175 | dev_err(&pdev->dev, "no platform data defined\n"); |
| 176 | error = -EINVAL; |
| 177 | goto err0; |
| 178 | } |
| 179 | |
| 180 | error = -ENXIO; |
| 181 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 182 | if (res == NULL) { |
| 183 | dev_err(&pdev->dev, "failed to get I/O memory\n"); |
| 184 | goto err0; |
| 185 | } |
| 186 | |
| 187 | irq = platform_get_irq(pdev, 0); |
| 188 | if (irq < 0) { |
| 189 | dev_err(&pdev->dev, "failed to get irq\n"); |
| 190 | goto err0; |
| 191 | } |
| 192 | |
| 193 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 194 | if (priv == NULL) { |
| 195 | dev_err(&pdev->dev, "failed to allocate driver data\n"); |
| 196 | error = -ENOMEM; |
| 197 | goto err0; |
| 198 | } |
| 199 | |
| 200 | platform_set_drvdata(pdev, priv); |
| 201 | memcpy(&priv->pdata, pdev->dev.platform_data, sizeof(priv->pdata)); |
| 202 | pdata = &priv->pdata; |
| 203 | |
Magnus Damm | 3bf1276 | 2010-01-21 00:02:36 -0800 | [diff] [blame] | 204 | priv->iomem_base = ioremap_nocache(res->start, resource_size(res)); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 205 | if (priv->iomem_base == NULL) { |
| 206 | dev_err(&pdev->dev, "failed to remap I/O memory\n"); |
| 207 | error = -ENXIO; |
Tetsuya Mukawa | d3aa43a | 2008-07-19 07:46:53 +0900 | [diff] [blame] | 208 | goto err1; |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | priv->input = input_allocate_device(); |
| 212 | if (!priv->input) { |
| 213 | dev_err(&pdev->dev, "failed to allocate input device\n"); |
| 214 | error = -ENOMEM; |
Magnus Damm | b6d2a3e | 2011-04-28 09:32:44 -0700 | [diff] [blame] | 215 | goto err2; |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | input = priv->input; |
| 219 | input->evbit[0] = BIT_MASK(EV_KEY); |
| 220 | |
| 221 | input->name = pdev->name; |
| 222 | input->phys = "sh-keysc-keys/input0"; |
| 223 | input->dev.parent = &pdev->dev; |
| 224 | |
| 225 | input->id.bustype = BUS_HOST; |
| 226 | input->id.vendor = 0x0001; |
| 227 | input->id.product = 0x0001; |
| 228 | input->id.version = 0x0100; |
| 229 | |
Dmitry Torokhov | 24d01c0 | 2009-07-21 01:12:12 -0700 | [diff] [blame] | 230 | input->keycode = pdata->keycodes; |
| 231 | input->keycodesize = sizeof(pdata->keycodes[0]); |
| 232 | input->keycodemax = ARRAY_SIZE(pdata->keycodes); |
| 233 | |
Magnus Damm | 2dfb9a8 | 2011-04-28 09:34:32 -0700 | [diff] [blame] | 234 | error = request_threaded_irq(irq, NULL, sh_keysc_isr, IRQF_ONESHOT, |
| 235 | dev_name(&pdev->dev), pdev); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 236 | if (error) { |
| 237 | dev_err(&pdev->dev, "failed to request IRQ\n"); |
Magnus Damm | b6d2a3e | 2011-04-28 09:32:44 -0700 | [diff] [blame] | 238 | goto err3; |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 239 | } |
| 240 | |
Dmitry Torokhov | 24d01c0 | 2009-07-21 01:12:12 -0700 | [diff] [blame] | 241 | for (i = 0; i < SH_KEYSC_MAXKEYS; i++) |
| 242 | __set_bit(pdata->keycodes[i], input->keybit); |
| 243 | __clear_bit(KEY_RESERVED, input->keybit); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 244 | |
| 245 | error = input_register_device(input); |
| 246 | if (error) { |
| 247 | dev_err(&pdev->dev, "failed to register input device\n"); |
Magnus Damm | b6d2a3e | 2011-04-28 09:32:44 -0700 | [diff] [blame] | 248 | goto err4; |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 249 | } |
| 250 | |
Magnus Damm | b6d2a3e | 2011-04-28 09:32:44 -0700 | [diff] [blame] | 251 | pm_runtime_enable(&pdev->dev); |
| 252 | pm_runtime_get_sync(&pdev->dev); |
Magnus Damm | 090d951 | 2008-10-31 20:21:23 +0900 | [diff] [blame] | 253 | |
Magnus Damm | 2b14a80 | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 254 | sh_keysc_write(priv, KYCR1, (sh_keysc_mode[pdata->mode].kymd << 8) | |
| 255 | pdata->scan_timing); |
| 256 | sh_keysc_level_mode(priv, 0); |
Magnus Damm | a29b99e | 2009-03-10 06:24:21 +0000 | [diff] [blame] | 257 | |
| 258 | device_init_wakeup(&pdev->dev, 1); |
Dmitry Torokhov | 24d01c0 | 2009-07-21 01:12:12 -0700 | [diff] [blame] | 259 | |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 260 | return 0; |
Dmitry Torokhov | 24d01c0 | 2009-07-21 01:12:12 -0700 | [diff] [blame] | 261 | |
Magnus Damm | 090d951 | 2008-10-31 20:21:23 +0900 | [diff] [blame] | 262 | err4: |
Magnus Damm | b6d2a3e | 2011-04-28 09:32:44 -0700 | [diff] [blame] | 263 | free_irq(irq, pdev); |
Magnus Damm | 090d951 | 2008-10-31 20:21:23 +0900 | [diff] [blame] | 264 | err3: |
Magnus Damm | b6d2a3e | 2011-04-28 09:32:44 -0700 | [diff] [blame] | 265 | input_free_device(input); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 266 | err2: |
Tetsuya Mukawa | d3aa43a | 2008-07-19 07:46:53 +0900 | [diff] [blame] | 267 | iounmap(priv->iomem_base); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 268 | err1: |
| 269 | platform_set_drvdata(pdev, NULL); |
| 270 | kfree(priv); |
| 271 | err0: |
| 272 | return error; |
| 273 | } |
| 274 | |
| 275 | static int __devexit sh_keysc_remove(struct platform_device *pdev) |
| 276 | { |
| 277 | struct sh_keysc_priv *priv = platform_get_drvdata(pdev); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 278 | |
Magnus Damm | 2b14a80 | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 279 | sh_keysc_write(priv, KYCR2, KYCR2_IRQ_DISABLED); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 280 | |
| 281 | input_unregister_device(priv->input); |
| 282 | free_irq(platform_get_irq(pdev, 0), pdev); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 283 | iounmap(priv->iomem_base); |
| 284 | |
Magnus Damm | b6d2a3e | 2011-04-28 09:32:44 -0700 | [diff] [blame] | 285 | pm_runtime_put_sync(&pdev->dev); |
| 286 | pm_runtime_disable(&pdev->dev); |
Magnus Damm | 090d951 | 2008-10-31 20:21:23 +0900 | [diff] [blame] | 287 | |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 288 | platform_set_drvdata(pdev, NULL); |
| 289 | kfree(priv); |
Dmitry Torokhov | 24d01c0 | 2009-07-21 01:12:12 -0700 | [diff] [blame] | 290 | |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 291 | return 0; |
| 292 | } |
| 293 | |
Dmitry Torokhov | cca8edf | 2011-07-04 06:34:48 -0700 | [diff] [blame] | 294 | #ifdef CONFIG_PM_SLEEP |
Magnus Damm | a29b99e | 2009-03-10 06:24:21 +0000 | [diff] [blame] | 295 | static int sh_keysc_suspend(struct device *dev) |
| 296 | { |
Magnus Damm | 4997692 | 2009-03-11 08:04:23 +0000 | [diff] [blame] | 297 | struct platform_device *pdev = to_platform_device(dev); |
| 298 | struct sh_keysc_priv *priv = platform_get_drvdata(pdev); |
Magnus Damm | 4ba50df | 2009-04-01 14:39:20 +0000 | [diff] [blame] | 299 | int irq = platform_get_irq(pdev, 0); |
Magnus Damm | a29b99e | 2009-03-10 06:24:21 +0000 | [diff] [blame] | 300 | unsigned short value; |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 301 | |
Magnus Damm | 2b14a80 | 2010-02-10 22:13:21 -0800 | [diff] [blame] | 302 | value = sh_keysc_read(priv, KYCR1); |
Magnus Damm | a29b99e | 2009-03-10 06:24:21 +0000 | [diff] [blame] | 303 | |
Magnus Damm | 4ba50df | 2009-04-01 14:39:20 +0000 | [diff] [blame] | 304 | if (device_may_wakeup(dev)) { |
Magnus Damm | b6d2a3e | 2011-04-28 09:32:44 -0700 | [diff] [blame] | 305 | sh_keysc_write(priv, KYCR1, value | 0x80); |
Magnus Damm | 4ba50df | 2009-04-01 14:39:20 +0000 | [diff] [blame] | 306 | enable_irq_wake(irq); |
Dmitry Torokhov | 24d01c0 | 2009-07-21 01:12:12 -0700 | [diff] [blame] | 307 | } else { |
Magnus Damm | b6d2a3e | 2011-04-28 09:32:44 -0700 | [diff] [blame] | 308 | sh_keysc_write(priv, KYCR1, value & ~0x80); |
| 309 | pm_runtime_put_sync(dev); |
Dmitry Torokhov | 24d01c0 | 2009-07-21 01:12:12 -0700 | [diff] [blame] | 310 | } |
Magnus Damm | a29b99e | 2009-03-10 06:24:21 +0000 | [diff] [blame] | 311 | |
Magnus Damm | a29b99e | 2009-03-10 06:24:21 +0000 | [diff] [blame] | 312 | return 0; |
| 313 | } |
| 314 | |
Magnus Damm | 4ba50df | 2009-04-01 14:39:20 +0000 | [diff] [blame] | 315 | static int sh_keysc_resume(struct device *dev) |
| 316 | { |
| 317 | struct platform_device *pdev = to_platform_device(dev); |
| 318 | int irq = platform_get_irq(pdev, 0); |
| 319 | |
| 320 | if (device_may_wakeup(dev)) |
| 321 | disable_irq_wake(irq); |
Magnus Damm | b6d2a3e | 2011-04-28 09:32:44 -0700 | [diff] [blame] | 322 | else |
| 323 | pm_runtime_get_sync(dev); |
Magnus Damm | 4ba50df | 2009-04-01 14:39:20 +0000 | [diff] [blame] | 324 | |
| 325 | return 0; |
| 326 | } |
Dmitry Torokhov | 9cc7c80 | 2011-05-04 20:54:27 -0700 | [diff] [blame] | 327 | #endif |
Magnus Damm | 4ba50df | 2009-04-01 14:39:20 +0000 | [diff] [blame] | 328 | |
Dmitry Torokhov | 9cc7c80 | 2011-05-04 20:54:27 -0700 | [diff] [blame] | 329 | static SIMPLE_DEV_PM_OPS(sh_keysc_dev_pm_ops, |
| 330 | sh_keysc_suspend, sh_keysc_resume); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 331 | |
Dmitry Torokhov | 12d0cef | 2011-05-02 23:09:19 -0700 | [diff] [blame] | 332 | static struct platform_driver sh_keysc_device_driver = { |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 333 | .probe = sh_keysc_probe, |
| 334 | .remove = __devexit_p(sh_keysc_remove), |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 335 | .driver = { |
| 336 | .name = "sh_keysc", |
Magnus Damm | a29b99e | 2009-03-10 06:24:21 +0000 | [diff] [blame] | 337 | .pm = &sh_keysc_dev_pm_ops, |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 338 | } |
| 339 | }; |
JJ Ding | 5146c84 | 2011-11-29 11:08:39 -0800 | [diff] [blame] | 340 | module_platform_driver(sh_keysc_device_driver); |
Magnus Damm | 795e6bf | 2008-03-04 15:23:45 -0800 | [diff] [blame] | 341 | |
| 342 | MODULE_AUTHOR("Magnus Damm"); |
| 343 | MODULE_DESCRIPTION("SuperH KEYSC Keypad Driver"); |
| 344 | MODULE_LICENSE("GPL"); |