From patchwork Sat Nov 7 15:12:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Praznik X-Patchwork-Id: 7575681 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2AC44C05C6 for ; Sat, 7 Nov 2015 15:12:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 474F3205B3 for ; Sat, 7 Nov 2015 15:12:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 624A4205B1 for ; Sat, 7 Nov 2015 15:12:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753555AbbKGPM4 (ORCPT ); Sat, 7 Nov 2015 10:12:56 -0500 Received: from mail-ig0-f180.google.com ([209.85.213.180]:36706 "EHLO mail-ig0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753464AbbKGPM4 (ORCPT ); Sat, 7 Nov 2015 10:12:56 -0500 Received: by igcph11 with SMTP id ph11so1921116igc.1 for ; Sat, 07 Nov 2015 07:12:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7YLkyi8dfYAvf180jh2zou9qQ/KmniEVOfOQpKh7lAQ=; b=fD4uvm55ZAI2RO6nv6nUdCYCIDh2zTu4c4YFvthc0doQZewhOgjUYvTEJbHbU3xDeo 2eZTW+ppjgyfia2p5/xrWGa+DkRgPJtuKENgAyIJLKhsRMNz/P4wBqdhlYHfQuBWLG4t vkN3zJzTj5FBNya5ZIyh/xK7H7EU3AKeC7kd2BHOOpUiKfYr2xdaqCJy2YutrAlx96qd 87DpobcvHsFFD42r5PTagb7VskNKNs89xqVC5w6m9a4V3bOjpKBYCSAVKB9+y6RirpcO pDt36zGneUCodHg2xcj2Hik3Qgue0FKZnUrXlmbTmbsSlwyLX9c6GIs8/K7a9OAoqLmg lz0A== X-Received: by 10.50.112.234 with SMTP id it10mr9819234igb.86.1446909175465; Sat, 07 Nov 2015 07:12:55 -0800 (PST) Received: from localhost.localdomain.localdomain (cpe-104-231-99-148.neo.res.rr.com. [104.231.99.148]) by smtp.gmail.com with ESMTPSA id yq7sm1676662igb.22.2015.11.07.07.12.54 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Nov 2015 07:12:55 -0800 (PST) From: Frank Praznik To: linux-input@vger.kernel.org Cc: jkosina@suse.cz, Frank Praznik Subject: [PATCH 2/2] hid: sony: Save and restore controller state on suspend and resume Date: Sat, 7 Nov 2015 10:12:10 -0500 Message-Id: <1446909130-9168-3-git-send-email-frank.praznik@gmail.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1446909130-9168-1-git-send-email-frank.praznik@gmail.com> References: <1446909130-9168-1-git-send-email-frank.praznik@gmail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On hardware which provides standby power for charging devices the state of the LEDs and force-feedback on controllers can persist even when the system is in standby. Additionally, the state of the controllers on resume may be different from the state they were in at the time when they were suspended (ie. LEDs remain off on resume). This implements the suspend and resume callbacks which saves and clears the state of the LEDs on suspend and restores it on resume. Force-feedback is stopped on suspend but automatically restored on resume until a new event is received to avoid potentially damaging hardware. Signed-off-by: Frank Praznik Acked-by: Antonio Ospite --- drivers/hid/hid-sony.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index b84b2ce..4eff8f7 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -1044,6 +1044,7 @@ struct sony_sc { __u8 battery_charging; __u8 battery_capacity; __u8 led_state[MAX_LEDS]; + __u8 resume_led_state[MAX_LEDS]; __u8 led_delay_on[MAX_LEDS]; __u8 led_delay_off[MAX_LEDS]; __u8 led_count; @@ -2427,6 +2428,48 @@ static void sony_remove(struct hid_device *hdev) hid_hw_stop(hdev); } +#ifdef CONFIG_PM + +static int sony_suspend(struct hid_device *hdev, pm_message_t message) +{ + /* + * On suspend save the current LED state, + * stop running force-feedback and blank the LEDS. + */ + if (SONY_LED_SUPPORT || SONY_FF_SUPPORT) { + struct sony_sc *sc = hid_get_drvdata(hdev); + +#ifdef CONFIG_SONY_FF + sc->left = sc->right = 0; +#endif + + memcpy(sc->resume_led_state, sc->led_state, + sizeof(sc->resume_led_state)); + memset(sc->led_state, 0, sizeof(sc->led_state)); + + sony_send_output_report(sc); + } + + return 0; +} + +static int sony_resume(struct hid_device *hdev) +{ + /* Restore the state of controller LEDs on resume */ + if (SONY_LED_SUPPORT) { + struct sony_sc *sc = hid_get_drvdata(hdev); + + memcpy(sc->led_state, sc->resume_led_state, + sizeof(sc->led_state)); + + sony_set_leds(sc); + } + + return 0; +} + +#endif + static const struct hid_device_id sony_devices[] = { { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER), .driver_data = SIXAXIS_CONTROLLER_USB }, @@ -2476,7 +2519,13 @@ static struct hid_driver sony_driver = { .probe = sony_probe, .remove = sony_remove, .report_fixup = sony_report_fixup, - .raw_event = sony_raw_event + .raw_event = sony_raw_event, + +#ifdef CONFIG_PM + .suspend = sony_suspend, + .resume = sony_resume, + .reset_resume = sony_resume, +#endif }; static int __init sony_init(void)