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