diff options
Diffstat (limited to 'drivers/input/misc/max8925_onkey.c')
-rw-r--r-- | drivers/input/misc/max8925_onkey.c | 115 |
1 files changed, 73 insertions, 42 deletions
diff --git a/drivers/input/misc/max8925_onkey.c b/drivers/input/misc/max8925_onkey.c index 23cf08271049..0a12b74140d3 100644 --- a/drivers/input/misc/max8925_onkey.c +++ b/drivers/input/misc/max8925_onkey.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /** | 1 | /** |
2 | * max8925_onkey.c - MAX8925 ONKEY driver | 2 | * MAX8925 ONKEY driver |
3 | * | 3 | * |
4 | * Copyright (C) 2009 Marvell International Ltd. | 4 | * Copyright (C) 2009 Marvell International Ltd. |
5 | * Haojian Zhuang <haojian.zhuang@marvell.com> | 5 | * Haojian Zhuang <haojian.zhuang@marvell.com> |
@@ -35,7 +35,7 @@ struct max8925_onkey_info { | |||
35 | struct input_dev *idev; | 35 | struct input_dev *idev; |
36 | struct i2c_client *i2c; | 36 | struct i2c_client *i2c; |
37 | struct device *dev; | 37 | struct device *dev; |
38 | int irq[2]; | 38 | unsigned int irq[2]; |
39 | }; | 39 | }; |
40 | 40 | ||
41 | /* | 41 | /* |
@@ -46,17 +46,14 @@ struct max8925_onkey_info { | |||
46 | static irqreturn_t max8925_onkey_handler(int irq, void *data) | 46 | static irqreturn_t max8925_onkey_handler(int irq, void *data) |
47 | { | 47 | { |
48 | struct max8925_onkey_info *info = data; | 48 | struct max8925_onkey_info *info = data; |
49 | int ret, event; | 49 | int state; |
50 | 50 | ||
51 | ret = max8925_reg_read(info->i2c, MAX8925_ON_OFF_STATUS); | 51 | state = max8925_reg_read(info->i2c, MAX8925_ON_OFF_STATUS); |
52 | if (ret & SW_INPUT) | 52 | |
53 | event = 1; | 53 | input_report_key(info->idev, KEY_POWER, state & SW_INPUT); |
54 | else | ||
55 | event = 0; | ||
56 | input_report_key(info->idev, KEY_POWER, event); | ||
57 | input_sync(info->idev); | 54 | input_sync(info->idev); |
58 | 55 | ||
59 | dev_dbg(info->dev, "onkey event:%d\n", event); | 56 | dev_dbg(info->dev, "onkey state:%d\n", state); |
60 | 57 | ||
61 | /* Enable hardreset to halt if system isn't shutdown on time */ | 58 | /* Enable hardreset to halt if system isn't shutdown on time */ |
62 | max8925_set_bits(info->i2c, MAX8925_SYSENSEL, | 59 | max8925_set_bits(info->i2c, MAX8925_SYSENSEL, |
@@ -69,6 +66,7 @@ static int __devinit max8925_onkey_probe(struct platform_device *pdev) | |||
69 | { | 66 | { |
70 | struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); | 67 | struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); |
71 | struct max8925_onkey_info *info; | 68 | struct max8925_onkey_info *info; |
69 | struct input_dev *input; | ||
72 | int irq[2], error; | 70 | int irq[2], error; |
73 | 71 | ||
74 | irq[0] = platform_get_irq(pdev, 0); | 72 | irq[0] = platform_get_irq(pdev, 0); |
@@ -76,6 +74,7 @@ static int __devinit max8925_onkey_probe(struct platform_device *pdev) | |||
76 | dev_err(&pdev->dev, "No IRQ resource!\n"); | 74 | dev_err(&pdev->dev, "No IRQ resource!\n"); |
77 | return -EINVAL; | 75 | return -EINVAL; |
78 | } | 76 | } |
77 | |||
79 | irq[1] = platform_get_irq(pdev, 1); | 78 | irq[1] = platform_get_irq(pdev, 1); |
80 | if (irq[1] < 0) { | 79 | if (irq[1] < 0) { |
81 | dev_err(&pdev->dev, "No IRQ resource!\n"); | 80 | dev_err(&pdev->dev, "No IRQ resource!\n"); |
@@ -83,11 +82,24 @@ static int __devinit max8925_onkey_probe(struct platform_device *pdev) | |||
83 | } | 82 | } |
84 | 83 | ||
85 | info = kzalloc(sizeof(struct max8925_onkey_info), GFP_KERNEL); | 84 | info = kzalloc(sizeof(struct max8925_onkey_info), GFP_KERNEL); |
86 | if (!info) | 85 | input = input_allocate_device(); |
87 | return -ENOMEM; | 86 | if (!info || !input) { |
87 | error = -ENOMEM; | ||
88 | goto err_free_mem; | ||
89 | } | ||
88 | 90 | ||
91 | info->idev = input; | ||
89 | info->i2c = chip->i2c; | 92 | info->i2c = chip->i2c; |
90 | info->dev = &pdev->dev; | 93 | info->dev = &pdev->dev; |
94 | info->irq[0] = irq[0]; | ||
95 | info->irq[1] = irq[1]; | ||
96 | |||
97 | input->name = "max8925_on"; | ||
98 | input->phys = "max8925_on/input0"; | ||
99 | input->id.bustype = BUS_I2C; | ||
100 | input->dev.parent = &pdev->dev; | ||
101 | input_set_capability(input, EV_KEY, KEY_POWER); | ||
102 | |||
91 | irq[0] += chip->irq_base; | 103 | irq[0] += chip->irq_base; |
92 | irq[1] += chip->irq_base; | 104 | irq[1] += chip->irq_base; |
93 | 105 | ||
@@ -96,60 +108,46 @@ static int __devinit max8925_onkey_probe(struct platform_device *pdev) | |||
96 | if (error < 0) { | 108 | if (error < 0) { |
97 | dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", | 109 | dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", |
98 | irq[0], error); | 110 | irq[0], error); |
99 | goto out; | 111 | goto err_free_mem; |
100 | } | 112 | } |
113 | |||
101 | error = request_threaded_irq(irq[1], NULL, max8925_onkey_handler, | 114 | error = request_threaded_irq(irq[1], NULL, max8925_onkey_handler, |
102 | IRQF_ONESHOT, "onkey-up", info); | 115 | IRQF_ONESHOT, "onkey-up", info); |
103 | if (error < 0) { | 116 | if (error < 0) { |
104 | dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", | 117 | dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", |
105 | irq[1], error); | 118 | irq[1], error); |
106 | goto out_irq; | 119 | goto err_free_irq0; |
107 | } | 120 | } |
108 | 121 | ||
109 | info->idev = input_allocate_device(); | ||
110 | if (!info->idev) { | ||
111 | dev_err(chip->dev, "Failed to allocate input dev\n"); | ||
112 | error = -ENOMEM; | ||
113 | goto out_input; | ||
114 | } | ||
115 | |||
116 | info->idev->name = "max8925_on"; | ||
117 | info->idev->phys = "max8925_on/input0"; | ||
118 | info->idev->id.bustype = BUS_I2C; | ||
119 | info->idev->dev.parent = &pdev->dev; | ||
120 | info->irq[0] = irq[0]; | ||
121 | info->irq[1] = irq[1]; | ||
122 | info->idev->evbit[0] = BIT_MASK(EV_KEY); | ||
123 | info->idev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER); | ||
124 | |||
125 | |||
126 | error = input_register_device(info->idev); | 122 | error = input_register_device(info->idev); |
127 | if (error) { | 123 | if (error) { |
128 | dev_err(chip->dev, "Can't register input device: %d\n", error); | 124 | dev_err(chip->dev, "Can't register input device: %d\n", error); |
129 | goto out_reg; | 125 | goto err_free_irq1; |
130 | } | 126 | } |
131 | 127 | ||
132 | platform_set_drvdata(pdev, info); | 128 | platform_set_drvdata(pdev, info); |
129 | device_init_wakeup(&pdev->dev, 1); | ||
133 | 130 | ||
134 | return 0; | 131 | return 0; |
135 | 132 | ||
136 | out_reg: | 133 | err_free_irq1: |
137 | input_free_device(info->idev); | 134 | free_irq(irq[1], info); |
138 | out_input: | 135 | err_free_irq0: |
139 | free_irq(info->irq[1], info); | 136 | free_irq(irq[0], info); |
140 | out_irq: | 137 | err_free_mem: |
141 | free_irq(info->irq[0], info); | 138 | input_free_device(input); |
142 | out: | ||
143 | kfree(info); | 139 | kfree(info); |
140 | |||
144 | return error; | 141 | return error; |
145 | } | 142 | } |
146 | 143 | ||
147 | static int __devexit max8925_onkey_remove(struct platform_device *pdev) | 144 | static int __devexit max8925_onkey_remove(struct platform_device *pdev) |
148 | { | 145 | { |
149 | struct max8925_onkey_info *info = platform_get_drvdata(pdev); | 146 | struct max8925_onkey_info *info = platform_get_drvdata(pdev); |
147 | struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); | ||
150 | 148 | ||
151 | free_irq(info->irq[0], info); | 149 | free_irq(info->irq[0] + chip->irq_base, info); |
152 | free_irq(info->irq[1], info); | 150 | free_irq(info->irq[1] + chip->irq_base, info); |
153 | input_unregister_device(info->idev); | 151 | input_unregister_device(info->idev); |
154 | kfree(info); | 152 | kfree(info); |
155 | 153 | ||
@@ -158,10 +156,43 @@ static int __devexit max8925_onkey_remove(struct platform_device *pdev) | |||
158 | return 0; | 156 | return 0; |
159 | } | 157 | } |
160 | 158 | ||
159 | #ifdef CONFIG_PM_SLEEP | ||
160 | static int max8925_onkey_suspend(struct device *dev) | ||
161 | { | ||
162 | struct platform_device *pdev = to_platform_device(dev); | ||
163 | struct max8925_onkey_info *info = platform_get_drvdata(pdev); | ||
164 | struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); | ||
165 | |||
166 | if (device_may_wakeup(dev)) { | ||
167 | chip->wakeup_flag |= 1 << info->irq[0]; | ||
168 | chip->wakeup_flag |= 1 << info->irq[1]; | ||
169 | } | ||
170 | |||
171 | return 0; | ||
172 | } | ||
173 | |||
174 | static int max8925_onkey_resume(struct device *dev) | ||
175 | { | ||
176 | struct platform_device *pdev = to_platform_device(dev); | ||
177 | struct max8925_onkey_info *info = platform_get_drvdata(pdev); | ||
178 | struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); | ||
179 | |||
180 | if (device_may_wakeup(dev)) { | ||
181 | chip->wakeup_flag &= ~(1 << info->irq[0]); | ||
182 | chip->wakeup_flag &= ~(1 << info->irq[1]); | ||
183 | } | ||
184 | |||
185 | return 0; | ||
186 | } | ||
187 | #endif | ||
188 | |||
189 | static SIMPLE_DEV_PM_OPS(max8925_onkey_pm_ops, max8925_onkey_suspend, max8925_onkey_resume); | ||
190 | |||
161 | static struct platform_driver max8925_onkey_driver = { | 191 | static struct platform_driver max8925_onkey_driver = { |
162 | .driver = { | 192 | .driver = { |
163 | .name = "max8925-onkey", | 193 | .name = "max8925-onkey", |
164 | .owner = THIS_MODULE, | 194 | .owner = THIS_MODULE, |
195 | .pm = &max8925_onkey_pm_ops, | ||
165 | }, | 196 | }, |
166 | .probe = max8925_onkey_probe, | 197 | .probe = max8925_onkey_probe, |
167 | .remove = __devexit_p(max8925_onkey_remove), | 198 | .remove = __devexit_p(max8925_onkey_remove), |