From patchwork Fri Feb 3 00:21:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roderick Colenbrander X-Patchwork-Id: 9553389 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 49F86604E2 for ; Fri, 3 Feb 2017 00:21:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39CEB205F6 for ; Fri, 3 Feb 2017 00:21:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2ED6E223B2; Fri, 3 Feb 2017 00:21:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 462ED21F61 for ; Fri, 3 Feb 2017 00:21:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751931AbdBCAVh (ORCPT ); Thu, 2 Feb 2017 19:21:37 -0500 Received: from mail-pf0-f174.google.com ([209.85.192.174]:33911 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751823AbdBCAVg (ORCPT ); Thu, 2 Feb 2017 19:21:36 -0500 Received: by mail-pf0-f174.google.com with SMTP id e4so1096616pfg.1 for ; Thu, 02 Feb 2017 16:21:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaikai-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=q0NlnbDQQ6dno1o2MoffiBOc9RZ6Dkpp/7eVv7xltuI=; b=fI9XZh2rdhawoznoD0x3zHbB7aN3s4+r33cdVmt8CYrnHoriCJPx9qDF/dzgE6fuLS M5MHyaoHryRm8ixpHrS7Zc5rzSgVRGb5hbdGrG5DVJHmj0z9Dv1OSCFVkjhx/InYlYHf 7tRxd5rtQPfJFjuS1ZPu2gk3f6fAPhbnDayu+LgUB7AMY11/BNVehM7R//7YDnzbhEoa sH2Aa4nyDhNz5gwHRWZXADrxXG9YK31NSGWBRHByCNjV9ckb59cWGqQrhEaT2mRqXZ7t Q02curw5/yPwApKYb6asVdzDK/bah9tllNBCMSaANVbSEm6JNL7lEPsH2u+TDvGjIx7k 24Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=q0NlnbDQQ6dno1o2MoffiBOc9RZ6Dkpp/7eVv7xltuI=; b=HVNqmjfC9+8wnbXOM7HrXIN69cu0rhclac6cmbjr5bgTdwQyhY0fu6dOG7aMlXXfQc zaMolBiIkwlWIrFoBxTL8NDr6kOQY9Ur9rtg6P8Fb5grO62HT2LaxW6CaIy045aCwsNl hkzCLpW6uS1bN0/irUtG5GqtDSEiq8a+cOmF6NhQA8jCagyOLBk70UdmRO5ZfijIgq3j 3A+DZ6nEoB2zcvVb2bMCWmsTQbibAvGfWxvtG9D/4qIMxdCX1pcuLXR/XgAnUj2bpPbZ rmQnw8zbO+xEpsEFGus9VrTgDeEXfZ1ihIPLR+FuAn/w0i0+QFaZ0vk1/R9J1UkZDl0R J9eA== X-Gm-Message-State: AIkVDXLyxRB7oityP6If7l6Sll+BQItVvtbmEJMWbKyjzRid1ClOqFr3CZnc+NDpAXoFw3Fg X-Received: by 10.98.194.22 with SMTP id l22mr14317823pfg.178.1486081295444; Thu, 02 Feb 2017 16:21:35 -0800 (PST) Received: from konan1.dev.biz ([100.42.98.197]) by smtp.gmail.com with ESMTPSA id x81sm61343282pff.69.2017.02.02.16.21.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Feb 2017 16:21:34 -0800 (PST) From: Roderick Colenbrander To: linux-input@vger.kernel.org Cc: Dmitry Torokhov , Jiri Kosina , Benjamin Tissoires , Simon Wood , Frank Praznik , Tim Bird , Roderick Colenbrander Subject: [PATCH 6/7] HID: sony: Make work handling more generic Date: Thu, 2 Feb 2017 16:21:05 -0800 Message-Id: <20170203002106.23225-7-roderick@gaikai.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170203002106.23225-1-roderick@gaikai.com> References: <20170203002106.23225-1-roderick@gaikai.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Roderick Colenbrander The driver currently uses sony_schedule_work to submit output reports for the different devices for LEDs or rumble. This patch adds a new parameter to sony_schedule_work to allow scheduling for other types of work. The next patch in this series will utilize this functionality. Considering the driver structure and all error handling it felt best to reuse sony_schedule_work and sony_cancel_work. The idea was inspired by the wacom driver which does something similar. Signed-off-by: Roderick Colenbrander --- drivers/hid/hid-sony.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index 60f801e..11e32eb 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -624,6 +624,10 @@ struct ds4_calibration_data { int sens_denom; }; +enum sony_worker { + SONY_WORKER_STATE +}; + struct sony_sc { spinlock_t lock; struct list_head list_node; @@ -645,7 +649,7 @@ struct sony_sc { #endif u8 mac_address[6]; - u8 worker_initialized; + u8 state_worker_initialized; u8 defer_initialization; u8 cable_state; u8 battery_charging; @@ -667,10 +671,14 @@ struct sony_sc { static void sony_set_leds(struct sony_sc *sc); -static inline void sony_schedule_work(struct sony_sc *sc) +static inline void sony_schedule_work(struct sony_sc *sc, + enum sony_worker which) { - if (!sc->defer_initialization) - schedule_work(&sc->state_worker); + switch (which) { + case SONY_WORKER_STATE: + if (!sc->defer_initialization) + schedule_work(&sc->state_worker); + } } static u8 *sixaxis_fixup(struct hid_device *hdev, u8 *rdesc, @@ -1104,7 +1112,7 @@ static int sony_raw_event(struct hid_device *hdev, struct hid_report *report, if (sc->defer_initialization) { sc->defer_initialization = 0; - sony_schedule_work(sc); + sony_schedule_work(sc, SONY_WORKER_STATE); } return 0; @@ -1585,7 +1593,7 @@ static void buzz_set_leds(struct sony_sc *sc) static void sony_set_leds(struct sony_sc *sc) { if (!(sc->quirks & BUZZ_CONTROLLER)) - sony_schedule_work(sc); + sony_schedule_work(sc, SONY_WORKER_STATE); else buzz_set_leds(sc); } @@ -1696,7 +1704,7 @@ static int sony_led_blink_set(struct led_classdev *led, unsigned long *delay_on, new_off != drv_data->led_delay_off[n]) { drv_data->led_delay_on[n] = new_on; drv_data->led_delay_off[n] = new_off; - sony_schedule_work(drv_data); + sony_schedule_work(drv_data, SONY_WORKER_STATE); } return 0; @@ -2025,7 +2033,7 @@ static int sony_play_effect(struct input_dev *dev, void *data, sc->left = effect->u.rumble.strong_magnitude / 256; sc->right = effect->u.rumble.weak_magnitude / 256; - sony_schedule_work(sc); + sony_schedule_work(sc, SONY_WORKER_STATE); return 0; } @@ -2346,15 +2354,15 @@ static inline void sony_init_output_report(struct sony_sc *sc, { sc->send_output_report = send_output_report; - if (!sc->worker_initialized) + if (!sc->state_worker_initialized) INIT_WORK(&sc->state_worker, sony_state_worker); - sc->worker_initialized = 1; + sc->state_worker_initialized = 1; } static inline void sony_cancel_work_sync(struct sony_sc *sc) { - if (sc->worker_initialized) + if (sc->state_worker_initialized) cancel_work_sync(&sc->state_worker); }