From patchwork Wed Oct 25 00:40:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10025545 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 4868360245 for ; Wed, 25 Oct 2017 00:40:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38E1828AB5 for ; Wed, 25 Oct 2017 00:40:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D64028AB8; Wed, 25 Oct 2017 00:40:24 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable 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 BB08228AB5 for ; Wed, 25 Oct 2017 00:40:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751821AbdJYAkK (ORCPT ); Tue, 24 Oct 2017 20:40:10 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:56586 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751682AbdJYAkJ (ORCPT ); Tue, 24 Oct 2017 20:40:09 -0400 Received: by mail-io0-f196.google.com with SMTP id m81so25789683ioi.13; Tue, 24 Oct 2017 17:40:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=z3pZ2cJTy2PeqmEgtQYUcs1pYlypcWwzv/TNRM8dSD0=; b=iTUgSjiWbfghsBpbtCetraDtBtVANLXoSzkPHEP4Ifl1IEj+hqpNtjPAVjDT5TEP7n iFpdNkxuy8fg1msQgrAX+OCUPVoCs/oWgOR2oHuGCaH2fPWlh9g4w1W5IwOc0iEU1nZH ycomutiKXBXV+AolAI9tDeIy9VVkvsPN326P3fdKNC5/1fv8R0wPp9FGTeblksvY1Omd aKuOitbQbDPVUaNqt57+aUbbItC5y5zzD7QDTP7nAM3tRYEKXKhIPf1xJa+bFaeQBTl9 5fBKgylraRMGn7Wve6YnI3OmNKkpqpm4buQG0gmfB0IpzkAuBu8F7bRVZljDzPlFQSLL q1Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=z3pZ2cJTy2PeqmEgtQYUcs1pYlypcWwzv/TNRM8dSD0=; b=R3Xns4x3CjrDlpTNHKRjOCIYGq2tmuqVO/8JnmH0K3h6D5mBHoQFeXitZA2oI03/lp nYa/0XiPHMSjmeLXmHCVvMxOkHXFOv2nb+OZTukp6fip+osWkDu5OdxLmAS0nvb9SUA5 omgM7lj1LwrVNpZ0REkvbHB55TxOh2hcXnXH4XvmBV0UbuI4+IN7YEA9W3FE/VXCDDll xEaS2oerdBpovim3aHC6vtzsvrpGa1RdSgEobZUpDL6Hwj5B5sGPo31GJVOj9H0Rhxgh XWwS/2SkYk7Sa9esUIYble638175hqeUspd5cRRNN8jPJOhxuUCJEqjI9/rlWP1NC1FQ LX6A== X-Gm-Message-State: AMCzsaU2ywUYk6DA8xBDSxeWqZF6N7+vdfUX3Ec9awHp1RFvBaKlXv7P CLrv/Z7uJS8Cpk3hQm3eaZA= X-Google-Smtp-Source: ABhQp+RCO/LwoyPe64kr4lzSd7tdqBQ2YscPZxCWT59eGoIJ52/bm/rFAP4PsEpxWNXrZuza1O8gFw== X-Received: by 10.107.38.79 with SMTP id m76mr24287803iom.187.1508892008293; Tue, 24 Oct 2017 17:40:08 -0700 (PDT) Received: from dtor-ws ([2620:0:1000:1611:da80:8749:c06f:9515]) by smtp.gmail.com with ESMTPSA id n135sm734084itg.29.2017.10.24.17.40.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Oct 2017 17:40:07 -0700 (PDT) Date: Tue, 24 Oct 2017 17:40:05 -0700 From: Dmitry Torokhov To: Mauro Carvalho Chehab Cc: Hans Verkuil , Kees Cook , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] media: av7110: switch to useing timer_setup() Message-ID: <20171025004005.hyb43h3yvovp4is2@dtor-ws> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In preparation for unconditionally passing the struct timer_list pointer to all timer callbacks, switch to using the new timer_setup() and from_timer() to pass the timer pointer explicitly. Also stop poking into input core internals and override its autorepeat timer function. I am not sure why we have such convoluted autorepeat handling in this driver instead of letting input core handle autorepeat, but this preserves current behavior of allowing controlling autorepeat delay and forcing autorepeat period to be whatever the hardware has. Signed-off-by: Dmitry Torokhov Reviewed-by: Kees Cook --- Note that this has not been tested on the hardware. But it should compile, so I have that going for me. drivers/media/pci/ttpci/av7110.h | 4 ++-- drivers/media/pci/ttpci/av7110_ir.c | 40 +++++++++++++++++-------------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/drivers/media/pci/ttpci/av7110.h b/drivers/media/pci/ttpci/av7110.h index 347827925c14..0aa3c6f01853 100644 --- a/drivers/media/pci/ttpci/av7110.h +++ b/drivers/media/pci/ttpci/av7110.h @@ -80,10 +80,11 @@ struct av7110; /* infrared remote control */ struct infrared { - u16 key_map[256]; + u16 key_map[256]; struct input_dev *input_dev; char input_phys[32]; struct timer_list keyup_timer; + unsigned long keydown_time; struct tasklet_struct ir_tasklet; void (*ir_handler)(struct av7110 *av7110, u32 ircom); u32 ir_command; @@ -93,7 +94,6 @@ struct infrared { u8 inversion; u16 last_key; u16 last_toggle; - u8 delay_timer_finished; }; diff --git a/drivers/media/pci/ttpci/av7110_ir.c b/drivers/media/pci/ttpci/av7110_ir.c index ca05198de2c2..b602e64b3412 100644 --- a/drivers/media/pci/ttpci/av7110_ir.c +++ b/drivers/media/pci/ttpci/av7110_ir.c @@ -84,9 +84,9 @@ static u16 default_key_map [256] = { /* key-up timer */ -static void av7110_emit_keyup(unsigned long parm) +static void av7110_emit_keyup(struct timer_list *t) { - struct infrared *ir = (struct infrared *) parm; + struct infrared *ir = from_timer(ir, keyup_timer, t); if (!ir || !test_bit(ir->last_key, ir->input_dev->key)) return; @@ -152,19 +152,20 @@ static void av7110_emit_key(unsigned long parm) return; } - if (timer_pending(&ir->keyup_timer)) { - del_timer(&ir->keyup_timer); + if (del_timer(&ir->keyup_timer)) { if (ir->last_key != keycode || toggle != ir->last_toggle) { - ir->delay_timer_finished = 0; + ir->keydown_time = jiffies; input_event(ir->input_dev, EV_KEY, ir->last_key, 0); input_event(ir->input_dev, EV_KEY, keycode, 1); input_sync(ir->input_dev); - } else if (ir->delay_timer_finished) { + } else if (time_after(jiffies, ir->keydown_time + + msecs_to_jiffies( + ir->input_dev->rep[REP_PERIOD]))) { input_event(ir->input_dev, EV_KEY, keycode, 2); input_sync(ir->input_dev); } } else { - ir->delay_timer_finished = 0; + ir->keydown_time = jiffies; input_event(ir->input_dev, EV_KEY, keycode, 1); input_sync(ir->input_dev); } @@ -172,9 +173,7 @@ static void av7110_emit_key(unsigned long parm) ir->last_key = keycode; ir->last_toggle = toggle; - ir->keyup_timer.expires = jiffies + UP_TIMEOUT; - add_timer(&ir->keyup_timer); - + mod_timer(&ir->keyup_timer, jiffies + UP_TIMEOUT); } @@ -184,12 +183,19 @@ static void input_register_keys(struct infrared *ir) int i; set_bit(EV_KEY, ir->input_dev->evbit); - set_bit(EV_REP, ir->input_dev->evbit); set_bit(EV_MSC, ir->input_dev->evbit); set_bit(MSC_RAW, ir->input_dev->mscbit); set_bit(MSC_SCAN, ir->input_dev->mscbit); + set_bit(EV_REP, ir->input_dev->evbit); + /* + * By setting the delay before registering input device we + * indicate that we will be implementing the autorepeat + * ourselves. + */ + ir->input_dev->rep[REP_DELAY] = 250; + memset(ir->input_dev->keybit, 0, sizeof(ir->input_dev->keybit)); for (i = 0; i < ARRAY_SIZE(ir->key_map); i++) { @@ -205,15 +211,6 @@ static void input_register_keys(struct infrared *ir) } -/* called by the input driver after rep[REP_DELAY] ms */ -static void input_repeat_key(unsigned long parm) -{ - struct infrared *ir = (struct infrared *) parm; - - ir->delay_timer_finished = 1; -} - - /* check for configuration changes */ int av7110_check_ir_config(struct av7110 *av7110, int force) { @@ -333,8 +330,7 @@ int av7110_ir_init(struct av7110 *av7110) av_list[av_cnt++] = av7110; av7110_check_ir_config(av7110, true); - setup_timer(&av7110->ir.keyup_timer, av7110_emit_keyup, - (unsigned long)&av7110->ir); + timer_setup(&av7110->ir.keyup_timer, av7110_emit_keyup, 0); input_dev = input_allocate_device(); if (!input_dev)