History

platform/chrome: cros_ec_lpc: Separate host command and irq disable

Both cros host command and irq disable were moved to suspend prepare stage from late suspend recently. This is causing EC to report MKBP event timeouts during suspend stress testing. When the MKBP event timeouts happen during suspend, subsequent wakeup of AP by EC using MKBP doesn't happen properly. Move the irq disabling part back to late suspend stage which is a general suggestion from the suspend kernel documentaiton to do irq disable as late as possible.

Lalith Rajendran committed 3 years ago

Commit 47ea0dd1 parent 466f70f3 files · +116 −26Browse files

Unified · Split

3 files
  1. drivers/platform/chrome/cros_ec.c +94 −22
  2. drivers/platform/chrome/cros_ec.h +4 −0
  3. drivers/platform/chrome/cros_ec_lpc.c +18 −4
drivers/platform/chrome/cros_ec.c+94−22
@@ -321,17 +321,8 @@ void cros_ec_unregister(struct cros_ec_device *ec_dev) · 320 unmodified lines
321EXPORT_SYMBOL(cros_ec_unregister);321EXPORT_SYMBOL(cros_ec_unregister);
322 322
323#ifdef CONFIG_PM_SLEEP323#ifdef CONFIG_PM_SLEEP
324/**324static void cros_ec_send_suspend_event(struct cros_ec_device *ec_dev)
325 * cros_ec_suspend() - Handle a suspend operation for the ChromeOS EC device.
326 * @ec_dev: Device to suspend.
327 *
328 * This can be called by drivers to handle a suspend event.
329 *
330 * Return: 0 on success or negative error code.
331 */
332int cros_ec_suspend(struct cros_ec_device *ec_dev)
333{325{
334 struct device *dev = ec_dev->dev;
335 int ret;326 int ret;
336 u8 sleep_event;327 u8 sleep_event;
337 328
@@ -343,7 +334,26 @@ int cros_ec_suspend(struct cros_ec_device *ec_dev) · 5 unmodified lines
343 if (ret < 0)334 if (ret < 0)
344 dev_dbg(ec_dev->dev, "Error %d sending suspend event to ec\n",335 dev_dbg(ec_dev->dev, "Error %d sending suspend event to ec\n",
345 ret);336 ret);
337}
346 338
339/**
340 * cros_ec_suspend_prepare() - Handle a suspend prepare operation for the ChromeOS EC device.
341 * @ec_dev: Device to suspend.
342 *
343 * This can be called by drivers to handle a suspend prepare stage of suspend.
344 *
345 * Return: 0 always.
346 */
347int cros_ec_suspend_prepare(struct cros_ec_device *ec_dev)
348{
349 cros_ec_send_suspend_event(ec_dev);
350 return 0;
351}
352EXPORT_SYMBOL(cros_ec_suspend_prepare);
353
354static void cros_ec_disable_irq(struct cros_ec_device *ec_dev)
355{
356 struct device *dev = ec_dev->dev;
347 if (device_may_wakeup(dev))357 if (device_may_wakeup(dev))
348 ec_dev->wake_enabled = !enable_irq_wake(ec_dev->irq);358 ec_dev->wake_enabled = !enable_irq_wake(ec_dev->irq);
349 else359 else
@@ -351,7 +361,35 @@ int cros_ec_suspend(struct cros_ec_device *ec_dev) · 1 unmodified line
351 361
352 disable_irq(ec_dev->irq);362 disable_irq(ec_dev->irq);
353 ec_dev->suspended = true;363 ec_dev->suspended = true;
364}
354 365
366/**
367 * cros_ec_suspend_late() - Handle a suspend late operation for the ChromeOS EC device.
368 * @ec_dev: Device to suspend.
369 *
370 * This can be called by drivers to handle a suspend late stage of suspend.
371 *
372 * Return: 0 always.
373 */
374int cros_ec_suspend_late(struct cros_ec_device *ec_dev)
375{
376 cros_ec_disable_irq(ec_dev);
377 return 0;
378}
379EXPORT_SYMBOL(cros_ec_suspend_late);
380
381/**
382 * cros_ec_suspend() - Handle a suspend operation for the ChromeOS EC device.
383 * @ec_dev: Device to suspend.
384 *
385 * This can be called by drivers to handle a suspend event.
386 *
387 * Return: 0 always.
388 */
389int cros_ec_suspend(struct cros_ec_device *ec_dev)
390{
391 cros_ec_send_suspend_event(ec_dev);
392 cros_ec_disable_irq(ec_dev);
355 return 0;393 return 0;
356}394}
357EXPORT_SYMBOL(cros_ec_suspend);395EXPORT_SYMBOL(cros_ec_suspend);
@@ -370,22 +408,11 @@ static void cros_ec_report_events_during_suspend(struct cros_ec_device *ec_dev) · 12 unmodified lines
370 }408 }
371}409}
372 410
373/**411static void cros_ec_send_resume_event(struct cros_ec_device *ec_dev)
374 * cros_ec_resume() - Handle a resume operation for the ChromeOS EC device.
375 * @ec_dev: Device to resume.
376 *
377 * This can be called by drivers to handle a resume event.
378 *
379 * Return: 0 on success or negative error code.
380 */
381int cros_ec_resume(struct cros_ec_device *ec_dev)
382{412{
383 int ret;413 int ret;
384 u8 sleep_event;414 u8 sleep_event;
385 415
386 ec_dev->suspended = false;
387 enable_irq(ec_dev->irq);
388
389 sleep_event = (!IS_ENABLED(CONFIG_ACPI) || pm_suspend_via_firmware()) ?416 sleep_event = (!IS_ENABLED(CONFIG_ACPI) || pm_suspend_via_firmware()) ?
390 HOST_SLEEP_EVENT_S3_RESUME :417 HOST_SLEEP_EVENT_S3_RESUME :
391 HOST_SLEEP_EVENT_S0IX_RESUME;418 HOST_SLEEP_EVENT_S0IX_RESUME;
@@ -394,6 +421,24 @@ int cros_ec_resume(struct cros_ec_device *ec_dev) · 2 unmodified lines
394 if (ret < 0)421 if (ret < 0)
395 dev_dbg(ec_dev->dev, "Error %d sending resume event to ec\n",422 dev_dbg(ec_dev->dev, "Error %d sending resume event to ec\n",
396 ret);423 ret);
424}
425
426/**
427 * cros_ec_resume_complete() - Handle a resume complete operation for the ChromeOS EC device.
428 * @ec_dev: Device to resume.
429 *
430 * This can be called by drivers to handle a resume complete stage of resume.
431 */
432void cros_ec_resume_complete(struct cros_ec_device *ec_dev)
433{
434 cros_ec_send_resume_event(ec_dev);
435}
436EXPORT_SYMBOL(cros_ec_resume_complete);
437
438static void cros_ec_enable_irq(struct cros_ec_device *ec_dev)
439{
440 ec_dev->suspended = false;
441 enable_irq(ec_dev->irq);
397 442
398 if (ec_dev->wake_enabled)443 if (ec_dev->wake_enabled)
399 disable_irq_wake(ec_dev->irq);444 disable_irq_wake(ec_dev->irq);
@@ -403,8 +448,35 @@ int cros_ec_resume(struct cros_ec_device *ec_dev) · 3 unmodified lines
403 * suspend. This way the clients know what to do with them.448 * suspend. This way the clients know what to do with them.
404 */449 */
405 cros_ec_report_events_during_suspend(ec_dev);450 cros_ec_report_events_during_suspend(ec_dev);
451}
406 452
453/**
454 * cros_ec_resume_early() - Handle a resume early operation for the ChromeOS EC device.
455 * @ec_dev: Device to resume.
456 *
457 * This can be called by drivers to handle a resume early stage of resume.
458 *
459 * Return: 0 always.
460 */
461int cros_ec_resume_early(struct cros_ec_device *ec_dev)
462{
463 cros_ec_enable_irq(ec_dev);
464 return 0;
465}
466EXPORT_SYMBOL(cros_ec_resume_early);
407 467
468/**
469 * cros_ec_resume() - Handle a resume operation for the ChromeOS EC device.
470 * @ec_dev: Device to resume.
471 *
472 * This can be called by drivers to handle a resume event.
473 *
474 * Return: 0 always.
475 */
476int cros_ec_resume(struct cros_ec_device *ec_dev)
477{
478 cros_ec_enable_irq(ec_dev);
479 cros_ec_send_resume_event(ec_dev);
408 return 0;480 return 0;
409}481}
410EXPORT_SYMBOL(cros_ec_resume);482EXPORT_SYMBOL(cros_ec_resume);
drivers/platform/chrome/cros_ec.h+4−0
@@ -16,7 +16,11 @@ int cros_ec_register(struct cros_ec_device *ec_dev); · 15 unmodified lines
16void cros_ec_unregister(struct cros_ec_device *ec_dev);16void cros_ec_unregister(struct cros_ec_device *ec_dev);
17 17
18int cros_ec_suspend(struct cros_ec_device *ec_dev);18int cros_ec_suspend(struct cros_ec_device *ec_dev);
19int cros_ec_suspend_late(struct cros_ec_device *ec_dev);
20int cros_ec_suspend_prepare(struct cros_ec_device *ec_dev);
19int cros_ec_resume(struct cros_ec_device *ec_dev);21int cros_ec_resume(struct cros_ec_device *ec_dev);
22int cros_ec_resume_early(struct cros_ec_device *ec_dev);
23void cros_ec_resume_complete(struct cros_ec_device *ec_dev);
20 24
21irqreturn_t cros_ec_irq_thread(int irq, void *data);25irqreturn_t cros_ec_irq_thread(int irq, void *data);
22 26
drivers/platform/chrome/cros_ec_lpc.c+18−4
@@ -547,22 +547,36 @@ MODULE_DEVICE_TABLE(dmi, cros_ec_lpc_dmi_table); · 546 unmodified lines
547static int cros_ec_lpc_prepare(struct device *dev)547static int cros_ec_lpc_prepare(struct device *dev)
548{548{
549 struct cros_ec_device *ec_dev = dev_get_drvdata(dev);549 struct cros_ec_device *ec_dev = dev_get_drvdata(dev);
550 550 return cros_ec_suspend_prepare(ec_dev);
551 return cros_ec_suspend(ec_dev);
552}551}
553 552
554static void cros_ec_lpc_complete(struct device *dev)553static void cros_ec_lpc_complete(struct device *dev)
555{554{
556 struct cros_ec_device *ec_dev = dev_get_drvdata(dev);555 struct cros_ec_device *ec_dev = dev_get_drvdata(dev);
557 cros_ec_resume(ec_dev);556 cros_ec_resume_complete(ec_dev);
557}
558
559static int cros_ec_lpc_suspend_late(struct device *dev)
560{
561 struct cros_ec_device *ec_dev = dev_get_drvdata(dev);
562
563 return cros_ec_suspend_late(ec_dev);
564}
565
566static int cros_ec_lpc_resume_early(struct device *dev)
567{
568 struct cros_ec_device *ec_dev = dev_get_drvdata(dev);
569
570 return cros_ec_resume_early(ec_dev);
558}571}
559#endif572#endif
560 573
561static const struct dev_pm_ops cros_ec_lpc_pm_ops = {574static const struct dev_pm_ops cros_ec_lpc_pm_ops = {
562#ifdef CONFIG_PM_SLEEP575#ifdef CONFIG_PM_SLEEP
563 .prepare = cros_ec_lpc_prepare,576 .prepare = cros_ec_lpc_prepare,
564 .complete = cros_ec_lpc_complete577 .complete = cros_ec_lpc_complete,
565#endif578#endif
579 SET_LATE_SYSTEM_SLEEP_PM_OPS(cros_ec_lpc_suspend_late, cros_ec_lpc_resume_early)
566};580};
567 581
568static struct platform_driver cros_ec_lpc_driver = {582static struct platform_driver cros_ec_lpc_driver = {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t