.. | .. |
---|
191 | 191 | axp20x_pek->info->shutdown_mask, buf, count); |
---|
192 | 192 | } |
---|
193 | 193 | |
---|
194 | | -DEVICE_ATTR(startup, 0644, axp20x_show_attr_startup, axp20x_store_attr_startup); |
---|
195 | | -DEVICE_ATTR(shutdown, 0644, axp20x_show_attr_shutdown, |
---|
196 | | - axp20x_store_attr_shutdown); |
---|
| 194 | +static DEVICE_ATTR(startup, 0644, axp20x_show_attr_startup, |
---|
| 195 | + axp20x_store_attr_startup); |
---|
| 196 | +static DEVICE_ATTR(shutdown, 0644, axp20x_show_attr_shutdown, |
---|
| 197 | + axp20x_store_attr_shutdown); |
---|
197 | 198 | |
---|
198 | | -static struct attribute *axp20x_attributes[] = { |
---|
| 199 | +static struct attribute *axp20x_attrs[] = { |
---|
199 | 200 | &dev_attr_startup.attr, |
---|
200 | 201 | &dev_attr_shutdown.attr, |
---|
201 | 202 | NULL, |
---|
202 | 203 | }; |
---|
203 | | - |
---|
204 | | -static const struct attribute_group axp20x_attribute_group = { |
---|
205 | | - .attrs = axp20x_attributes, |
---|
206 | | -}; |
---|
| 204 | +ATTRIBUTE_GROUPS(axp20x); |
---|
207 | 205 | |
---|
208 | 206 | static irqreturn_t axp20x_pek_irq(int irq, void *pwr) |
---|
209 | 207 | { |
---|
210 | | - struct input_dev *idev = pwr; |
---|
211 | | - struct axp20x_pek *axp20x_pek = input_get_drvdata(idev); |
---|
| 208 | + struct axp20x_pek *axp20x_pek = pwr; |
---|
| 209 | + struct input_dev *idev = axp20x_pek->input; |
---|
| 210 | + |
---|
| 211 | + if (!idev) |
---|
| 212 | + return IRQ_HANDLED; |
---|
212 | 213 | |
---|
213 | 214 | /* |
---|
214 | 215 | * The power-button is connected to ground so a falling edge (dbf) |
---|
.. | .. |
---|
227 | 228 | static int axp20x_pek_probe_input_device(struct axp20x_pek *axp20x_pek, |
---|
228 | 229 | struct platform_device *pdev) |
---|
229 | 230 | { |
---|
230 | | - struct axp20x_dev *axp20x = axp20x_pek->axp20x; |
---|
231 | 231 | struct input_dev *idev; |
---|
232 | 232 | int error; |
---|
233 | | - |
---|
234 | | - axp20x_pek->irq_dbr = platform_get_irq_byname(pdev, "PEK_DBR"); |
---|
235 | | - if (axp20x_pek->irq_dbr < 0) { |
---|
236 | | - dev_err(&pdev->dev, "No IRQ for PEK_DBR, error=%d\n", |
---|
237 | | - axp20x_pek->irq_dbr); |
---|
238 | | - return axp20x_pek->irq_dbr; |
---|
239 | | - } |
---|
240 | | - axp20x_pek->irq_dbr = regmap_irq_get_virq(axp20x->regmap_irqc, |
---|
241 | | - axp20x_pek->irq_dbr); |
---|
242 | | - |
---|
243 | | - axp20x_pek->irq_dbf = platform_get_irq_byname(pdev, "PEK_DBF"); |
---|
244 | | - if (axp20x_pek->irq_dbf < 0) { |
---|
245 | | - dev_err(&pdev->dev, "No IRQ for PEK_DBF, error=%d\n", |
---|
246 | | - axp20x_pek->irq_dbf); |
---|
247 | | - return axp20x_pek->irq_dbf; |
---|
248 | | - } |
---|
249 | | - axp20x_pek->irq_dbf = regmap_irq_get_virq(axp20x->regmap_irqc, |
---|
250 | | - axp20x_pek->irq_dbf); |
---|
251 | 233 | |
---|
252 | 234 | axp20x_pek->input = devm_input_allocate_device(&pdev->dev); |
---|
253 | 235 | if (!axp20x_pek->input) |
---|
.. | .. |
---|
263 | 245 | |
---|
264 | 246 | input_set_drvdata(idev, axp20x_pek); |
---|
265 | 247 | |
---|
266 | | - error = devm_request_any_context_irq(&pdev->dev, axp20x_pek->irq_dbr, |
---|
267 | | - axp20x_pek_irq, 0, |
---|
268 | | - "axp20x-pek-dbr", idev); |
---|
269 | | - if (error < 0) { |
---|
270 | | - dev_err(&pdev->dev, "Failed to request dbr IRQ#%d: %d\n", |
---|
271 | | - axp20x_pek->irq_dbr, error); |
---|
272 | | - return error; |
---|
273 | | - } |
---|
274 | | - |
---|
275 | | - error = devm_request_any_context_irq(&pdev->dev, axp20x_pek->irq_dbf, |
---|
276 | | - axp20x_pek_irq, 0, |
---|
277 | | - "axp20x-pek-dbf", idev); |
---|
278 | | - if (error < 0) { |
---|
279 | | - dev_err(&pdev->dev, "Failed to request dbf IRQ#%d: %d\n", |
---|
280 | | - axp20x_pek->irq_dbf, error); |
---|
281 | | - return error; |
---|
282 | | - } |
---|
283 | | - |
---|
284 | 248 | error = input_register_device(idev); |
---|
285 | 249 | if (error) { |
---|
286 | 250 | dev_err(&pdev->dev, "Can't register input device: %d\n", |
---|
287 | 251 | error); |
---|
288 | 252 | return error; |
---|
289 | 253 | } |
---|
290 | | - |
---|
291 | | - if (axp20x_pek->axp20x->variant == AXP288_ID) |
---|
292 | | - enable_irq_wake(axp20x_pek->irq_dbr); |
---|
293 | 254 | |
---|
294 | 255 | return 0; |
---|
295 | 256 | } |
---|
.. | .. |
---|
348 | 309 | |
---|
349 | 310 | axp20x_pek->axp20x = dev_get_drvdata(pdev->dev.parent); |
---|
350 | 311 | |
---|
| 312 | + axp20x_pek->irq_dbr = platform_get_irq_byname(pdev, "PEK_DBR"); |
---|
| 313 | + if (axp20x_pek->irq_dbr < 0) |
---|
| 314 | + return axp20x_pek->irq_dbr; |
---|
| 315 | + axp20x_pek->irq_dbr = regmap_irq_get_virq( |
---|
| 316 | + axp20x_pek->axp20x->regmap_irqc, axp20x_pek->irq_dbr); |
---|
| 317 | + |
---|
| 318 | + axp20x_pek->irq_dbf = platform_get_irq_byname(pdev, "PEK_DBF"); |
---|
| 319 | + if (axp20x_pek->irq_dbf < 0) |
---|
| 320 | + return axp20x_pek->irq_dbf; |
---|
| 321 | + axp20x_pek->irq_dbf = regmap_irq_get_virq( |
---|
| 322 | + axp20x_pek->axp20x->regmap_irqc, axp20x_pek->irq_dbf); |
---|
| 323 | + |
---|
351 | 324 | if (axp20x_pek_should_register_input(axp20x_pek, pdev)) { |
---|
352 | 325 | error = axp20x_pek_probe_input_device(axp20x_pek, pdev); |
---|
353 | 326 | if (error) |
---|
.. | .. |
---|
356 | 329 | |
---|
357 | 330 | axp20x_pek->info = (struct axp20x_info *)match->driver_data; |
---|
358 | 331 | |
---|
359 | | - error = devm_device_add_group(&pdev->dev, &axp20x_attribute_group); |
---|
360 | | - if (error) { |
---|
361 | | - dev_err(&pdev->dev, "Failed to create sysfs attributes: %d\n", |
---|
362 | | - error); |
---|
| 332 | + error = devm_request_any_context_irq(&pdev->dev, axp20x_pek->irq_dbr, |
---|
| 333 | + axp20x_pek_irq, 0, |
---|
| 334 | + "axp20x-pek-dbr", axp20x_pek); |
---|
| 335 | + if (error < 0) { |
---|
| 336 | + dev_err(&pdev->dev, "Failed to request dbr IRQ#%d: %d\n", |
---|
| 337 | + axp20x_pek->irq_dbr, error); |
---|
363 | 338 | return error; |
---|
364 | 339 | } |
---|
365 | 340 | |
---|
| 341 | + error = devm_request_any_context_irq(&pdev->dev, axp20x_pek->irq_dbf, |
---|
| 342 | + axp20x_pek_irq, 0, |
---|
| 343 | + "axp20x-pek-dbf", axp20x_pek); |
---|
| 344 | + if (error < 0) { |
---|
| 345 | + dev_err(&pdev->dev, "Failed to request dbf IRQ#%d: %d\n", |
---|
| 346 | + axp20x_pek->irq_dbf, error); |
---|
| 347 | + return error; |
---|
| 348 | + } |
---|
| 349 | + |
---|
| 350 | + device_init_wakeup(&pdev->dev, true); |
---|
| 351 | + |
---|
366 | 352 | platform_set_drvdata(pdev, axp20x_pek); |
---|
| 353 | + |
---|
| 354 | + return 0; |
---|
| 355 | +} |
---|
| 356 | + |
---|
| 357 | +static int __maybe_unused axp20x_pek_suspend(struct device *dev) |
---|
| 358 | +{ |
---|
| 359 | + struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev); |
---|
| 360 | + |
---|
| 361 | + /* |
---|
| 362 | + * As nested threaded IRQs are not automatically disabled during |
---|
| 363 | + * suspend, we must explicitly disable non-wakeup IRQs. |
---|
| 364 | + */ |
---|
| 365 | + if (device_may_wakeup(dev)) { |
---|
| 366 | + enable_irq_wake(axp20x_pek->irq_dbf); |
---|
| 367 | + enable_irq_wake(axp20x_pek->irq_dbr); |
---|
| 368 | + } else { |
---|
| 369 | + disable_irq(axp20x_pek->irq_dbf); |
---|
| 370 | + disable_irq(axp20x_pek->irq_dbr); |
---|
| 371 | + } |
---|
| 372 | + |
---|
| 373 | + return 0; |
---|
| 374 | +} |
---|
| 375 | + |
---|
| 376 | +static int __maybe_unused axp20x_pek_resume(struct device *dev) |
---|
| 377 | +{ |
---|
| 378 | + struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev); |
---|
| 379 | + |
---|
| 380 | + if (device_may_wakeup(dev)) { |
---|
| 381 | + disable_irq_wake(axp20x_pek->irq_dbf); |
---|
| 382 | + disable_irq_wake(axp20x_pek->irq_dbr); |
---|
| 383 | + } else { |
---|
| 384 | + enable_irq(axp20x_pek->irq_dbf); |
---|
| 385 | + enable_irq(axp20x_pek->irq_dbr); |
---|
| 386 | + } |
---|
367 | 387 | |
---|
368 | 388 | return 0; |
---|
369 | 389 | } |
---|
.. | .. |
---|
387 | 407 | } |
---|
388 | 408 | |
---|
389 | 409 | static const struct dev_pm_ops axp20x_pek_pm_ops = { |
---|
| 410 | + SET_SYSTEM_SLEEP_PM_OPS(axp20x_pek_suspend, axp20x_pek_resume) |
---|
390 | 411 | #ifdef CONFIG_PM_SLEEP |
---|
391 | 412 | .resume_noirq = axp20x_pek_resume_noirq, |
---|
392 | 413 | #endif |
---|
.. | .. |
---|
411 | 432 | .driver = { |
---|
412 | 433 | .name = "axp20x-pek", |
---|
413 | 434 | .pm = &axp20x_pek_pm_ops, |
---|
| 435 | + .dev_groups = axp20x_groups, |
---|
414 | 436 | }, |
---|
415 | 437 | }; |
---|
416 | 438 | module_platform_driver(axp20x_pek_driver); |
---|