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