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